htaccess重定向完整网址(包括查询字符串)

时间:2014-07-08 09:27:54

标签: php apache .htaccess mod-rewrite redirect

目前我使用此代码重写我的网址:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 

网址http://www.website.com/test/被重定向到index.php?url=test/。我还希望将http://www.website.com/test.php?page=123重定向到index.php?url=test.php%3Fpage%3D123,以便我可以使用它来动态检测旧的重定向。怎么可以实现呢?

1 个答案:

答案 0 :(得分:1)

使用%{QUERY_STRING}

RewriteRule ^(.*)$ index.php?url=$1%{QUERY_STRING}

http://httpd.apache.org/docs/current/mod/mod_rewrite.html