URL重写和参数GET问题

时间:2013-10-24 16:30:01

标签: apache .htaccess mod-rewrite url-rewriting

我有一些问题要构建我的网址重写。在我的本地服务器上,使用nginx,一切进展顺利。但是一旦我试图让它apachehtacces一起工作,我就会变得疯狂。

我的网址看起来像这样:

  

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变量没有任何内容。我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:2)

在规则中使用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标志确保在添加新查询参数时保留现有查询字符串。