问题
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