我在构建 url 重写时遇到一些问题。在我的本地服务器上,使用 nginx
,一切都很顺利。但是,当我尝试使用 htacces
使其适用于 apache
时,我就有点发疯了。
我的网址如下所示:
http://example.com/controller/action/param1/value1/param2/value2
以下是适用于前一种情况的 htaccess
:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(images|css|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
但在某些情况下我有一些额外的参数,例如 Facebook 身份验证:
http://example.com/controller/action?hauth.start=Facebook&hauth.time=1382665465
此案例不适用于之前的 htaccess
。 GET 变量中没有任何内容。我该如何解决这个问题?
最佳答案
在规则中使用QSA
(查询字符串附加)标志
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(images|css|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
QSA
标志确保在添加新查询参数时保留现有查询字符串。
关于apache - URL 重写和参数 GET 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19571541/