關於tp5 PATHINFO的URL重寫

官方給出的Apache重寫規則

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] </IfModule>

這個規則在apache fastcgi模式下會導致No input file specified.

修改成

RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

地址就正常重寫。

官方給出的Nginx 重寫規則在站點的vhosts.conf中修改

location / { // …..省略部分代碼 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; } }

其實質是將URL轉化爲兼容模式

http://serverName/index.php(或者其它應用入口文件)?s=/模塊/控制器/操作/[參數名/參數值...]

以解決老版本Nginx不支持PATHINFO模式

高版本可優化規則爲,當然可以不改

    location / {// …..省略部分代碼
          if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php/$1  last;
          }
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章