开发者

Mod_rewrite: Include query string when redirecting

I've got a small problem with mod_rewrite. This is my code:

RewriteEngine on 
RewriteRule ^(.*)$ http://newsite.com/moved.php?q=$1 [R=301,L]

This almost works, if I go to oldsite.com/apage.php, I get redirected to newsite.com/moved.php?q=apage.php.

However, if I go to oldsite.com/apage.php?var=15, I get redirected to newsite.com/moved.php?q=apage.php again.

How could I make ol开发者_C百科dsite.com/apage.php?var=15 redirect to newsite.com/moved.php?q=apage.php?var=15 Thanks a lot!


Use the QSA flag to get the original requested query automatically appended to the new one:

RewriteRule ^(.*)$ http://newsite.com/moved.php?q=$1 [R=301,L,QSA]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜