zoukankan      html  css  js  c++  java
  • Nginx 服务器伪静态配置实例

    具体的配置代码如下:

    rewrite ^/region/(.*).htm$  /index.php?regionid=$1 last;
    rewrite ^/trade/(.*).htm$   /index.php?m=trade&totalid=$1 last;
    rewrite ^/company.htm$        /index.php?m=company&a=index last;
    rewrite ^/company/order/([w]+).htm$            /index.php?m=company&a=index&order=$1 last;
    rewrite ^/company/order/([w]+)/page/([w+]).htm$  /index.php?m=company&a=index&order=$1&page=$2 last;
    rewrite ^/company/detail/([w]+).htm$           /index.php?m=company&a=detail&id=$1 last;
    rewrite ^/company/detail/([w]+)/([w]+).htm$      /index.php?m=company&a=detail&id=$1&detail=$2 last;
    rewrite ^/company/interview.htm$             /index.php?m=interview&a=index last;
    rewrite ^/company/interview/detail/(.*).htm$ /index.php?m=interview&a=detail&id=$1 last;
    rewrite ^/company/pic.htm$                   /index.php?m=hj&a=index last;
    rewrite ^/news.htm$                          /index.php?m=new&a=index last;
    rewrite ^/news/detail/(.*).htm$               /index.php?m=new&a=detail&artcile_id=$1 last;
    rewrite ^/([w]+)/([w]+).htm$               /index.php?$1=$2 last;
    rewrite ^/([w]+)/([w]+)/([w]+)/([w]+).htm$    /index.php?$1=$2&$3=$4 last;
    rewrite ^/([w]+)/([w]+)/([w]+)/([w]+)/([w]+)/([w]+).htm$  /index.php?$1=$2&$3=$4&$5=$6 last;
    rewrite ^/([w]+)/([w]+)/([w]+)/([w]+)/([w]+)/([w]+)/([w]+)/([w]+).htm(?)(.*)$   /index.php?$1=$2&$3=$4&$5=$6&$7=$8&$9 last;

    PHP生成对应的伪静态链接 虽然比较麻烦,但是灵活性很高...自己想怎么生成都可以,这个具体根据项目去配置。

     1 /**
     2  * 生成链接地址
     3  */
     4 function u($url)
     5 {    
     6     
     7     if(is_local()) //如果是本地不进行伪静态处理,直接返回原地址
     8     {
     9         if (!eregi("^http://",$url))
    10         {
    11             $web_url = get_web_url();
    12             $url = $web_url."/".$url;
    13         }
    14         return $url;
    15     
    16     }
    17     else  //网上进行url处理
    18     {
    19             //查询的数据分解
    20                 $urlArr = parse_url($url);
    21                 $host = $urlArr['scheme']."://".$urlArr['host'];
    22                 $urlQuery = explode("&",$urlArr['query']);
    23             //将传入的参数分割成一维数组的键值对模式
    24                 $paramArr = array();
    25                 foreach ($urlQuery as $v)
    26                 {
    27                     $tempArr = explode("=",$v);
    28                     $paramArr[$tempArr[0]] = $tempArr[1];
    29                     $urlStr.="/".$tempArr[0]."/".$tempArr[1];
    30                 }
    31             if (!empty($paramArr[regionid]))
    32             {
    33                 return $host."/region/{$paramArr[regionid]}".".htm";
    34             }
    35             elseif ($paramArr[m]=="trade")
    36             {
    37                 return $host."/trade/{$paramArr[totalid]}".".htm";
    38             }
    39             elseif ($paramArr[m]=="company" && $paramArr[a]=="index" && empty($paramArr[order]) && empty($paramArr[page]))
    40             {
    41                 return $host."/company.htm";
    42             }
    43             elseif ($paramArr[m]=="company" && $paramArr[a]=="index" && !empty($paramArr[order]) && empty($paramArr[page]))
    44             {
    45                 return $host."/company/order/{$paramArr[order]}.htm";
    46             }
    47             elseif ($paramArr[m]=="company" && $paramArr[a]=="index" && !empty($paramArr[order]) && !empty($paramArr[page]))
    48             {
    49                 return $host."/company/order/{$paramArr[order]}/page/{$paramArr[page]}.htm";
    50             }
    51             elseif ($paramArr[m]=="company" && $paramArr[a]=="detail" && empty($paramArr[detail]))
    52             {
    53                 return $host."/company/detail/{$paramArr[id]}.htm";
    54             }
    55             elseif ($paramArr[m]=="company" && $paramArr[a]=="detail" && !empty($paramArr[detail]))
    56             {
    57                 return $host."/company/detail/{$paramArr[id]}/{$paramArr[detail]}.htm";
    58             }
    59             elseif ($paramArr['m']=="interview" && $paramArr[a]=="index")
    60             {
    61                 return $host."/company/interview.htm";
    62             }
    63             elseif ($paramArr['m']=="interview" && $paramArr[a]=="detail")
    64             {
    65                 return $host."/company/interview/detail/{$paramArr[id]}.htm";
    66             }
    67             elseif ($paramArr['m']=="hj" && $paramArr['a']=="index" && empty($paramArr['order'] ) && empty($paramArr['page']))
    68             {
    69                 return $host."/company/pic.htm";
    70             }
    71             elseif ($paramArr['m']=="new" && $paramArr['a']=="index" && empty($paramArr['page']))
    72             {
    73                 return $host."/news.htm";
    74             }
    75             elseif ($paramArr['m']=="new" && $paramArr['a']=="detail")
    76             {
    77                 return $host."/news/detail/{$paramArr['artcile_id']}.htm";
    78             }
    79             else
    80             {
    81                 $urlStr.=".htm";
    82                 return $host.$urlStr;
    83             }
    84     }
    85 }
  • 相关阅读:
    对“一道有趣的题目”的解答
    在Debian中使用Notify
    Debian服务器安装详细流程
    Lighttpd1.4.20源码分析之插件系统(1)plugin结构体和插件接口
    Lighttpd1.4.20源码分析之etag.c(h) HTTP/1.1中的Etag域
    Lighttpd1.4.20源码分析之bitset.c(h) 位集合的使用
    伸展树
    GCC中的弱符号与强符号
    Lighttpd1.4.20源码分析之fdevent系统(3) 使用
    Lighttpd1.4.20源码分析之插件系统(3)PLUGIN_TO_SLOT宏
  • 原文地址:https://www.cnblogs.com/ypeih/p/3173182.html
Copyright © 2011-2022 走看看