htaccess重写查询字符串到$ _GET文件夹

时间:2015-08-18 19:36:31

标签: php regex .htaccess mod-rewrite

RewriteCond %{THE_REQUEST} \ /view\?i=([0-9]+)
RewriteRule ^ /view/%1? [L,R]

RewriteRule ^view/([0-9]+)$ /view?i=$1 [L]

这会将http://domain.com/view?i=40重写为http://domain.com/view/40

问题是,它似乎正在打破$_GET['i'](空)。这个答案来自SO。是什么造成的?

注意:我之前的重写规则是从网址中删除.php

1 个答案:

答案 0 :(得分:1)

尝试关闭选项MultiViews

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]

RewriteCond %{THE_REQUEST} \ /view\?i=([0-9]+)
RewriteRule ^ /view/%1? [L,R]

RewriteRule ^view/([0-9]+)$ /view?i=$1 [NC,L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

MultiViews使用选项Apache's content negotiation modulemod_rewrite之前运行,并使Apache服务器匹配文件扩展名。因此/file可以在网址中,但它会投放/file.php