3

I have 2 different domains (www.mysite.com and www.mysite.it) associated at 2 different Store View (code=en and code=it). After set from backend my Magento 1.9.0.1 to works with different domains, I set my .htaccess to redirect to the right store view and the right associated domain:

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

This works well except for one thing:

if I type mysite.com/myproduct-name or mysite.it/myproduct-name without www it brings me to the respective homepage (www.mysite.com and www.mysite.it).

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


Edit

Ok, I think this is the problem, this is hot .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

Where am I wrong?

3 Answers 3

2

This is the trick:

    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

and you need to set in System-->Configuration-->Web-->Auto-redirect to Base URL-->NO

Thank you all

1
  • 1
    This worked great for me. I use an always-on HTTPS connection so changing the http%1 in the last line to just https solved my issue.
    – Steven J
    Commented Jul 13, 2017 at 17:03
1

A simple rewrite will address that.

RewriteCond %{HTTP_HOST} ^mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301]
6
  • Thank you. I have tried but still redirect on the homepage.
    – KaMZaTa
    Commented Nov 6, 2014 at 0:59
  • Rewrite rules are processed before the Magento redirect. If you are experiencing a redirect, then its either your browser cache, or the rewrite rule hasn't been implemented correctly. Commented Nov 6, 2014 at 1:09
  • I clear all browser cache, open it in a different browser in anonymous window. Furthermore, RewriteEngine On and the above rewrite directive are write before Mage SetEnvIf (although they are processed before).
    – KaMZaTa
    Commented Nov 6, 2014 at 1:18
  • I also tried as mentioned in this post (stackoverflow.com/questions/12317177/…
    – KaMZaTa
    Commented Nov 6, 2014 at 2:00
  • Checking site with this tool I received a warning of "potential duplicated content" for / and /index.php. In fact and more precisely address mysite.com/myproduct-name take me to /index.php
    – KaMZaTa
    Commented Nov 6, 2014 at 2:30
-1

Note that the MAGE_RUN_CODE value should correspond with the store view code!

[Edit] If you can edit your vhost config, you could just use SetEnv for each vhost https://httpd.apache.org/docs/2.4/mod/mod_env.html#setenv

2
  • That's what OP stated in the question. Commented Jan 24, 2016 at 12:43
  • You're absolutely correct, I just could not delete my post. Sorry for that!
    – Kasper Agg
    Commented Jan 24, 2016 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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