Jump to content

Redirect non-www url to www for multistore in 1.6


Recommended Posts

Hi there,

I have set up multi-store in Prestashop 1.6.0.6 and it works fine except for one detail, let me explain:

I have shop 1:
http://www.shop1.com

Shop 2:
http://www.shop2.com

If you go to http://shop1.com, it redirected to www.shop1.com (no issue) and if go to http://www.shop2.com then everything works ok. However if you go to http://shop2.com (without www) then you get redirected to http://www.shop1.com

That's obviously a big problem as it is likely some visitors will omit the www.
 

I parked the domain shop2.com on top of shop1.com using "Park domain" feature and shop1 is under root.

 

My .htaccess file is this

 

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.shop1.com$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

 

I have tried the below solution suggested by someone in one of the thread but it didn't work out and give 404 error on other pages, home page is fine.

 

" try this: add this to the top of your .htaccess file..ensures www

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

</IfModule>      

 

"

Does anyone able to help solve my problem? Very much appreciated your help. I have been spending hours to work this out but without luck. I am not technical guys :(

Thanks in advance :)          

Link to comment
Share on other sites

  • 2 months later...
<VirtualHost *:80>
    ServerAdmin webmaster@nfdexcom
    DocumentRoot "/var/www/html/xxxx.com"
    ServerName xxxx.com
    ServerAlias www.xxxx.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^xxxx\.com
     RewriteRule ^/(.*)$ http://www.xxxx.com/$1 [NC,R=301]
    ErrorLog "/var/log/httpd/xxxx.com-error.log"
    CustomLog "/var/log/httpd/xxxx.com-access.log" common
</VirtualHost>

hi,this is one  VirtualHost in vhost.conf

,you can try it, 

Edited by NFDex (see edit history)
Link to comment
Share on other sites

I guess you could try this ( I don't profess to know much, if anything about .htaccess files)

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


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

Edited by Chris2013 (see edit history)
Link to comment
Share on other sites

I tried both your .htaccess codes, but both don't work for me properly...

 

They work if I go like this:

 

shop2.com/site-1 -> http://www.shop2.com/site-1 -> correct

shop2.com/ -> http://www.shop1.com -> not correct

 

So the problem is that main url doesn't work. I checked also this:

 

shop2.com/index.php -> http://www.shop2.com -> correct

 

Any idea?

Link to comment
Share on other sites

If i am i correct the above rules redirect everything that is not www. i.e. shop1.com to www.shop1.com and shop2.com to www.shop2.com . I added the line to the top of the .htaccess file, right after :

 

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

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

Link to comment
Share on other sites

I had the same problem but now thanks to El Patron problem is solved.

 

I've change everything under the code RewriteEngine on. I had to remove the earlier code and its work.

 

My code in .htacces is:

 

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

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

usage note:

 

ps can get 'very' confused and create issues with items in cart being lost.

 

so if you use non-www to www

 

in preferences-->seo &  urls-->scroll down

 

make sure that shop and ssl domain has the  www.

 

(this  needs to be done if also if you do the revers, www to non-www)

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...