apache - Mod_重写: Include query string when redirecting

标签 apache mod-rewrite

我在 mod_rewrite 方面遇到了一个小问题。这是我的代码:

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

这几乎有效,如果我访问 oldsite.com/apage.php,我会被重定向到 newsite.com/moved.php?q=apage.php。
但是,如果我转到 oldsite.com/apage.php?var=15,我会再次重定向到 newsite.com/moved.php?q=apage.php。
我怎样才能使oldsite.com/apage.php?var=15重定向到newsite.com/moved.php?q=apage.php?var=15 非常感谢!

最佳答案

使用QSA flag将原始请求的查询自动附加到新查询中:

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

关于apache - Mod_重写: Include query string when redirecting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836355/

相关文章:

php - 如何执行扩展名为.html的php文件?

.htaccess - 为目录路由重写 url .htaccess GET-Parameter

python - Errno 13 Django 对我不想使用的目录的权限被拒绝

apache - mod_rewrite 神秘的子请求

apache - htaccess 将缺少的bundle.*.js 版本重定向到bundle.js 文件

java - org.apache.catalina.LifecycleException : Failed to initialize component [org. apache.catalina.webresources.JarResourceSet@4ae3c1cd]

php - .htaccess mod_rewrite 对于漂亮的网址不起作用

Mod-rewrite 恶作剧

.htaccess - PhpStorm 在做代码分析时能否解析.htaccess 中的mod_rewrite 规则?

php - 通过支持 HTTP_RANGE 的 Apache 和 PHP virtual() 函数发送文件