If I type mysite.com/myproduct-name or mysite.it/myproduct-name without www it brings me to the respective homepage (I have 2 domains: www.mysite.com and www.mysite.it).

.htaccess part:

RewriteCond %{HTTP_HOST} !^mysite.it$ [NC]
RewriteRule ^(.*)$ http://www.mysite.it/ [R=301,L]

# RewriteCond %{HTTP_HOST} !^mysite.com$ [NC]
# RewriteRule ^(.*)$ http://www.mysite.com/ [R=301,L]

SetEnvIf Host www\.mysite\.com MAGE_RUN_CODE=en
SetEnvIf Host ^mysite\.com MAGE_RUN_CODE=en
SetEnvIf Host www\.mysite\.it MAGE_RUN_CODE=it
SetEnvIf Host ^mysite\.it MAGE_RUN_CODE=it
  • In this situation redirect of product is resolved but I can access only to www.mysite.it
  • If I uncomment row 3 and 4 I'm not able to access both domains anymore.
  • If I remove ! from both conditions I can access to both domains but redirect to www product page doesn't work anymore

How can set it so that redirect me to the www version of the content (e.g. www.mysite.com/myproduct-name)?


Go to System->Configuration->Web->Url Options and set the field Auto-redirect to Base URL to No.

  • Thank you but, if I set this I can access both homepage version with and without www. I want access ONLY to the www version. – KaMZaTa Nov 6 '14 at 16:02
  • More specifically, doing this product redirect (mysite.com/myproduct --> www.mysite.com/myproduct) works but now home redirect doesn't (site.com --> site.com). – KaMZaTa Nov 6 '14 at 18:38
  • @KaMZaTa tou should be able to solve the home page issue with a rewrite rule. At least the rest of the pages work. – Marius Nov 6 '14 at 18:41
  • And how? I have different domains and condition rule ^mysite.it$ doesn't seems match. Only match !^mysite.it$ but doing this excludes also other domain. – KaMZaTa Nov 6 '14 at 18:58

First line in .htaccess needs to be changed to include www prefix (as there is negation in the condition). Redirect in the second line should include request URL, so it would be like:

RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC]
RewriteRule ^(.*)$ http://www.mysite.it/$1 [R=301,L]

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


RewriteCond %{HTTP_HOST} ^mysite\.it$ [NC]
RewriteRule ^ http://www.mysite.it%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^ http://www.mysite.com%{REQUEST_URI} [R=301,L]

Other non-matching requests you can redirect in similar way to www.mysite.com or www.mysite.it as needed.

  • Doing this way generates a loop between www.mysite.com and www.mysite.it – KaMZaTa Nov 6 '14 at 18:03
  • Thank you for pointing this out. I have corrected the answer assuming both domains are active. The previous reply was for single domain only. – Alex Grin Nov 6 '14 at 18:10
  • Doing this way I can access both domains but product page without www lead to homepage and not to itself. – KaMZaTa Nov 6 '14 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.