Aknot
Aknot

Reputation: 519

Magento multistore with htaccess rewrites for different domains

We had a old ecommerce site moved from a PrestaShop install to a new Magento setup/installation.

When we made this move, we added a lot of 301 rewrites in the htaccess, on the new Magento server, to reflect all the changed urls.

This is working flawless, but now we want to move and add another domain and setup a multistore environment, on this new Magento installation.

How can we make these new 301 rules, for this new domain, be run only when accessing the new domain, and don't interfere withe the previous rewrites, for the original domain?

This is basically what we have now:

# OLD DOMAIN REWRITE RULES ON MAGENTO SERVER
RewriteRule ^oldurl1.html(.*)$      /new-nice-url1/?    [R=301,NC,L]
RewriteRule ^oldurl2.html(.*)$      /new-nice-url2/?    [R=301,NC,L]
RewriteRule ^oldurl3.html(.*)$      /new-nice-url3/?    [R=301,NC,L]
...

This is what we have been trying to add:

# NEWLY ADDED DOMAIN TO MAGENTO MULTISTORE ENVIRONMENT
RewriteCond %{HTTP_HOST} ^www\.newdomain\.com
RewriteRule ^newdomain-old-url1.html(.*)$       /new-domain-url1/?   [R=301,NC,L]
RewriteRule ^newdomain-old-url2.html(.*)$       /new-domain-url2/?   [R=301,NC,L]
RewriteRule ^newdomain-old-url3.html(.*)$       /new-domain-url3/?   [R=301,NC,L]
...

But that doesn't seem to do the trick.

Upvotes: 0

Views: 781

Answers (1)

Drakes
Drakes

Reputation: 23670

From your question and comments, it sounds like you want to isolate rewrite rules for different domains. Try using a RewriteCond above each RewriteRule block, something like this:

# OLD DOMAIN REWRITE RULES ON MAGENTO SERVER
RewriteCond %{HTTP_HOST} !^(www\.)?newdomain\.com
RewriteRule ^oldurl1.html(.*)$      /new-nice-url1/?    [R=301,NC,L]
RewriteRule ^oldurl2.html(.*)$      /new-nice-url2/?    [R=301,NC,L]
RewriteRule ^oldurl3.html(.*)$      /new-nice-url3/?    [R=301,NC,L]

# NEWLY ADDED DOMAIN TO MAGENTO MULTISTORE ENVIRONMENT
RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com
RewriteRule ^newdomain-old-url1.html(.*)$       /new-domain-url1/?   [R=301,NC,L]
RewriteRule ^newdomain-old-url2.html(.*)$       /new-domain-url2/?   [R=301,NC,L]
RewriteRule ^newdomain-old-url3.html(.*)$       /new-domain-url3/?   [R=301,NC,L]

You could also use this condition to preserve your old domain rewrites:

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com

Please feel free to try out these rules in an online .htaccess tester.

Upvotes: 1

Related Questions