关于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;
          }
    }

猜你喜欢

转载自my.oschina.net/u/3104120/blog/1619200