mod_rewrite的:重定向时包含查询字符串 [英] Mod_rewrite: Include query string when redirecting
问题描述
我有一个小问题,mod_rewrite的。这是我的code:
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]
这几乎是工作,如果我去oldsite.com/apage.php~~V,我重定向到newsite.com/moved.php?q=apage.php~~V。结果
但是,如果我去oldsite.com/apage.php?var=15~~V,我重定向再次newsite.com/moved.php?q=apage.php~~V。结果
我如何才能让oldsite.com/apage.php?var=15重定向到newsite.com/moved.php?q=apage.php?var=15
非常感谢!
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!
推荐答案
使用的 QSA 的标志获得自动添加到新的原始请求查询:
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]
这篇关于mod_rewrite的:重定向时包含查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!