简体   繁体   中英

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

to

http:// folder1 .mywonderfulwebsite.com/ whatever-url-as-above .php

Question is: many times, an external website links the page with GET parameters, for example

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:

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:

www.mywonderfulwebsite.com/folder1/ atextfile.txt

Redirects to

folder1.mywonderfulwebsite.com/ atextfile.txt&

In fact, the mod_rewrite appends the trailing &

How do I fix this issue? How to correctly redirecting to the correct ( also with GET parameters ) url?

Many thanks

只需将[QSA]标志添加到其他标志中,即可自动重置[Q] uery [S] tring [A]。

[L,R=301,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM