I'm having some trouble setting up a htaccess file. Currently I have 15 domains serving their own website. Now moving this to a single website and domain, I want to serve a htaccess with 301 rules for the old urls. The destination url depends on the domainname of the old url..


http://www.previouswebsiteinspanish.com/contacto should be permanently rewritten to http://www.newcentralwebsite.eu/es/contact

I understand that I have to use the RewriteCond but I'm not familiar enough with it to get it working.

RewriteCond %{HTTP_REFERER} !^http://(www\.)?previouswebsiteinspanish/.*$ [NC]
RewriteRule ^([^/.]+)/contacto$ /$1/contact [R=301,L]

Thanks in advance!

Accepted Answer

You current condition is that the rule will be executed under the condition that the referring page is not on the old domain. That's most likely not what you want to do. :)

You want to check the %{HTTP_HOST} parameter, which contains only the hostname part of the currently requested URL.

Assuming you want to redirect everything on the old domain to the es subfolder, this rule will do it.

RewriteCond %{HTTP_HOST} ^(www\.)?previouswebsiteinspanish.com$ [NC]
RewriteRule ^(.*)$ http://www.newcentralwebsite.eu/es/$1 [R=301,L]

Then you'll have to add similar rules for each old domain.

Written by nitro2k01
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki