This question probably has been answered, but I cannot seem to find a fitting solution.
I would like to 301 redirect all pages like the ones below
http://www.domain1.com/nl/dolor/sith
http://www.domain1.com/nl/loremipsum
http://www.domain1.com/nl
To a new domain, and at the same time drop the querystring, like so:
http://www.domain2.nl
All other pages, such as http://www.domain1.com/be/loremipsum should still work. Only the ones with suffix nl
should redirect.
Please note that these are not real directories: in my .htaccess file I've got the following statements to rewrite my query string:
# Personal Rewrites
RewriteRule ^([A-Za-z0-9-_]+)/?$ index.php?lid=$1 [L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ index.php?lid=$1&pl1=$2 [L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ index.php?lid=$1&pl1=$2&pl2=$3 [L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ index.php?lid=$1&pl1=$2&pl2=$3&pl3=$4 [L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ index.php?lid=$1&pl1=$2&pl2=$3&pl3=$4&pl4=$5 [L]
RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ index.php?lid=$1&pl1=$2&pl2=$3&pl3=$4&pl4=$5&pl5=$6 [L]
I've tried the traditional rewrite, but this also sends the querystring:
Redirect 301 /nl http://www.domain2.nl
Other techniques do not seem to work. And I'm not good at regexes...
Could someone give or link to a fitting solution? Thanks in advance
Add this rule as the first rule in your DOCUMENT_ROOT/.htaccess:
RewriteRule ^nl(/.*|)$ http://www.domain2.nl/? [L,R=301,NC]
Another tip about regex:
You should change your regex to use: [\w-]
instead of [A-Za-z0-9-_]
since:
\w
is equivalent of [a-zA-Z0-9_]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With