[英]Maintaining the query string with mod_rewrite
I've correctly configured my website to re-route every piece of traffic from 我已正确配置我的网站以重新路由来自的每个流量
mywonderfulwebsite.com/ folder1 / whatever-url .php mywonderfulwebsite.com/ folder1 / whatever-url .php
to 至
http:// folder1 .mywonderfulwebsite.com/ whatever-url-as-above .php http:// folder1 .mywonderfulwebsite.com / whatever-url-as-above .php
Question is: many times, an external website links the page with GET parameters, for example 问题是:很多时候,外部网站将页面与GET参数链接起来
mywonderfulwebsite.com/folder1/whatever-url.php* ?trackingToken=1 * mywonderfulwebsite.com/folder1/whatever-url.php*?trackingToken = 1 *
So, question is how to make the mod_rewrite pass in the GET parameters to the "rewrited" url, like this: 所以,问题是如何让mod_rewrite在GET参数中传递给“重写”的url,如下所示:
folder1.mywonderfulwebsite.com/whatever-url-as-above.php* ?trackingToken=1 * folder1.mywonderfulwebsite.com/whatever-url-as-above.php*?trackingToken = 1 *
Currently, I'm doing the following: 目前,我正在做以下事情:
<VirtualHost *>
ServerName mywonderfulwebsite.com
ServerAlias www.mywonderfulwebsite.com
DocumentRoot /var/www/mywonderfulwebsite/
DirectoryIndex index.html
<Directory />
allow from all
Options +FollowSymlinks -Indexes
</Directory>
RewriteEngine On
RewriteRule ^/folder1/(.*)?$ http://folder1.mywonderfulwebsite.com/$1&%{QUERY_STRING} [L,R=301]
</VirtualHost>
This piece of htaccess is awful: for example, trying to access this url: 这段htaccess非常糟糕:例如,试图访问这个网址:
www.mywonderfulwebsite.com/folder1/ atextfile.txt www.mywonderfulwebsite.com/folder1/ atextfile.txt
Redirects to 重定向到
folder1.mywonderfulwebsite.com/ atextfile.txt& folder1.mywonderfulwebsite.com/ atextfile.txt&
In fact, the mod_rewrite appends the trailing & 实际上,mod_rewrite会附加尾随&
How do I fix this issue? 我该如何解决这个问题? How to correctly redirecting to the correct ( also with GET parameters ) url?
如何正确地重定向到正确的(也使用GET参数)url?
Many thanks 非常感谢
只需将[QSA]标志添加到其他标志中,即可自动重置[Q] uery [S] tring [A]。
[L,R=301,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.