Issue
We would like to redirect all trafic to our new page. We would still like that ceratin urls are still accessible on our old page, because these are used by our partners and are not yet ready to migrate.
The problem i'm having is with QUERY_STRING parameters.
My rules so far:
RewriteCond %{REQUEST_URI} !^/endfile.php
RewriteCond %{REQUEST_URI} !^/sites/default/files/pdffolder/
RewriteCond %{REQUEST_URI} !^/insure/agency
# RewriteCond %{REQUEST_URI} !^/content/insurance1?szs=000029&wssl=1
# RewriteCond %{REQUEST_URI} !^/text/insurance2?wssl=1&zst=enter
RewriteRule (.*) https://www.new-domain.eu/ [R=301,L]
The code works for the fist 3. I cant get it to work for the 4th and 5th rule. I currently have the commented out.
I tried using QUERY_STRING rules, without success. Is htere any way to use AND in rewrite condition?
Any ideas?
Solution
You cannot match query string using REQUEST_URI
. Use THE_REQUEST
to match both URI and query:
RewriteCond %{REQUEST_URI} !^/endfile\.php [NC]
RewriteCond %{REQUEST_URI} !^/sites/default/files/pdffolder/ [NC]
RewriteCond %{REQUEST_URI} !^/insure/agency [NC]
RewriteCond %{THE_REQUEST} !\s/+content/insurance1\?szs=000029&wssl=1[&\s] [NC]
RewriteCond %{THE_REQUEST} !\s/+text/insurance2\?wssl=1&zst=enter[&\s] [NC]
RewriteRule ^ https://www.new-domain.eu/? [R=301,L]
Also note use of trailing ?
in target to strip off any existing query string.
Answered By - anubhava