I have a special use case where I need to redirect URL's starting with a few keywords to the base URL.
So for example I want to redirect:
/test1 to /?utm_campaign=test1
and
/test2 to /?utm_campaign=test2
This works fine using this rule:
RewriteEngine On
RewriteBase /
RewriteRule ^(test1|test2) ?utm_campaign=$1 [R=301,L]
But I also want to preserve other query string parameters, so:
/test1?utm_content=abc should redirect to /?utm_campaign=test1&utm_content=abc
I've tried it with QSA, which works in Chrome, but not Safari:
RewriteEngine On
RewriteBase /
RewriteRule ^(test1|test2) ?utm_campaign=$1 [R=301,L,QSA]
Chrome redirects it correctly, but Safari just redirects to /?utm_campaign=test1
I've also tried adding the full query string to the target URL, like so: /?utm_campaign=test1&q=
This also works in Chrome, but not safari, using this rule:
RewriteEngine On
RewriteBase /
RewriteRule ^(test1|test2) ?utm_campaign=$1&q=%{QUERY_STRING} [R=301,L]
Any ideas how to append my query string parameters to the target URL?
Edit: The problem turned out not to be with the rewrite rules, but with caching of the url parameters on the hosting side. I've had the hosting company add some caching exclusions and after that everything works as expected.