Mod_rewrite: Include query string when redirecting

十年热恋 提交于 2019-12-24 01:47:08

问题


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 oldsite.com/apage.php?var=15 redirect to newsite.com/moved.php?q=apage.php?var=15 Thanks a lot!


回答1:


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]


来源:https://stackoverflow.com/questions/4836355/mod-rewrite-include-query-string-when-redirecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!