欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

歡迎來到云服務器

服務器租用

Nginx處事器下利用rewrite重寫url以實現偽靜態的示例

顛末網上查閱和測試,發明Nginx的Rewrite法則和Apache的Rewite法則不同不是很大,險些可以直接利用。好比在Apache中這樣寫法則

rewrite ^/([0-9]{5}).html$ /viewthread.php?tid=$1 last;

而在Nginx中寫成這樣寫是無法啟動的,辦理的步伐是加上兩個雙引號:

rewrite "^/([0-9]{5}).html$" /viewthread.php?tid=$1 last;

同時將RewriteRule為Rewrite,,根基就實現了Nginx的Rewrite法則到Apache的Rewite法則的轉換。

Rewrite的Flags

last - 根基上都用這個Flag。

break - 中止Rewirte,不在繼承匹配

redirect - 返回姑且重定向的HTTP狀態302

permanent - 返回永久重定向的HTTP狀態301

WordPress的Rewrite
其實在Nginx下設置WordPress的Rewrite照舊較量簡樸的,在location /{..................}內里插手

if (!-f $request_filename){
rewrite (.*) /index.php;
}

即可實現

下面是一個完整的vhost的設置文件

server {
listen 80;
server_name server110.com www.server110.com;
location / {
    index index.html index.htm index.php;
    root /www/wwwroot/server110.com;
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }
}
location ~ .php$ {
    include fastcgi_params;
    fastcgi_index index.php;
    fastcgi_pass 127.0.0.1:8787;
    fastcgi_param SCRIPT_FILENAME /www/wwwroot/server110.com$fastcgi_script_name;
    }
location /server110-status {
    stub_status on;
    access_log off;
    }
}

Discuz!的Rewrite
下面的Rewrite中百分號前面多了個轉移字符“”,這在Apache中是需要的,而在Nginx中則是不需要的。

rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;

正確的應該是

rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;

這個錯誤在根基上今朝所有利用Nginx作為處事器,而且開啟了Rewrite的網站上存在。包羅Discuz!官方,今朝已經給cnteacher反饋了。
Nginx實例代碼

server {
  listen    80;
  server_name www.server110.com server110.com;
  location / {
     index      index.html index.htm index.php;
     root      /www/www.server110.com;
     rewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last;
     rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;
     rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last;
     rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;
     rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;
     rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;
  }
    location ~ .php$ {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:8694;
        fastcgi_param SCRIPT_FILENAME /www/www.server110.com$fastcgi_script_name;
    }
  location /www.server110.com-status {
     stub_status on;
     access_log off;
  }
}

騰訊云代理

Copyright © 2003-2021 MFISP.COM. 國外vps服務器租用 夢飛云服務器租用 版權所有 ? 粵ICP備11019662號

主站蜘蛛池模板: 凉城县| 津南区| 双江| 佛坪县| 怀宁县| 保靖县| 张家口市| 阿荣旗| 定边县| 新化县| 原阳县| 扬中市| 景泰县| 新丰县| 门头沟区| 秀山| 清流县| 鄂温| 鹤岗市| 平顶山市| 东莞市| 巴楚县| 句容市| 七台河市| 凤凰县| 绵阳市| 竹山县| 嘉荫县| 辽源市| 安远县| 惠州市| 佛山市| 福鼎市| 柳州市| 南召县| 旌德县| 库车县| 岑巩县| 怀化市| 涟水县| 肇庆市|