Maintaining a query string using mod_rewrite

I correctly configured my site to redirect each piece of traffic from

mywonderfulwebsite.com/ folder1 /whatever-url.php

to

Http: // folder1 .mywonderfulwebsite.com / what-url-above.php

Question: many times an external website associates a page with GET parameters, for example

mywonderfulwebsite.com/folder1/whatever-url.php*?trackingToken=1 *

So the question is how to make mod_rewrite pass in the GET parameters for the "rewritten" URL, for example:

folder1.mywonderfulwebsite.com/whatever-url-as-above.php*?trackingToken=1 *

I am currently 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 htaccess snippet is terrible: for example, trying to access this URL:

www.mywonderfulwebsite.com/folder1/ atextfile.txt

folder1.mywonderfulwebsite.com/ atextfile.txt &

mod_rewrite &

? ( GET) url?

+3
1

[QSA] , [Q] uery [S] tring [A] .

[L,R=301,QSA]
+5

Source: https://habr.com/ru/post/1791264/


All Articles