cancel
Showing results for 
Search instead for 
Did you mean: 

PROBLEM: 'Auto-redirect to Base URL' redirects all non-www pages to www home page on a multi-site

SOLVED

PROBLEM: 'Auto-redirect to Base URL' redirects all non-www pages to www home page on a multi-site

Hi,

 

I want all non-www page to be redirected to the correct www version. E.g. 

siteB.com => www.siteB.com

siteB.com/any-page => www.siteB.com/any-page

siteB.com/another-page.html => www.siteB.com/another-page.html

 

Using Magento CE ver. 1.7.0.2 (old, I know).

The main website is siteA.com

Another magento website (not store) on the same setup is siteB.com

Base url for the second store is set to http://www.siteB.com for both secure and unsecure.

'Use Web Server Rewrites' is set to Yes.

When I set 'Auto-redirect to Base URL' to Yes, it redirects all pages (e.g. siteB.com, siteB.com/any-page, siteB.com/another-page.html, etc.) to www.siteB.com/index.php

It doesn't retain the part after the domain name and adds /index.php instead. Why is that?

Also, I have tried setting redirects in .htaccess in various ways and it's still redirecting to www.siteB.com/index.php (with and without 'Auto-redirect to Base URL' set to Yes).

Any idea what could be causing this??

 

 

Not sure if the below is related to the issue...

 

Sitemapping is not working in htaccess. E.g.:

RewriteCond %{HTTP_HOST} www\.siteB\.com [NC]
RewriteRule .* - [E=MAGE_RUN_CODE:websiteB]
RewriteCond %{HTTP_HOST} www\.siteB\.com [NC]
RewriteRule .* - [E=MAGE_RUN_TYPE:website]

or...

SetEnvIf Host www\.siteB\.com MAGE_RUN_CODE=websiteB
SetEnvIf Host www\.siteB\.com MAGE_RUN_TYPE=website

Therefore mapping was done in public_html/index.php like so:

// Redirect to correct site on domain
if($_SERVER['SERVER_NAME'] == "siteB.com" || $_SERVER['SERVER_NAME'] == "www.siteB.com" ){
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : 'websiteB';
} else {
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
}
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'website';
Mage::run($mageRunCode, $mageRunType);

Thanks Smiley Happy

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: PROBLEM: 'Auto-redirect to Base URL' redirects all non-www pages to www home page on a multi-sit

SOLVED

Apparently, the trick is to place redirection code at the very beginning of the htaccess file!!

I have used the following code:

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

View solution in original post

2 REPLIES 2

Re: PROBLEM: 'Auto-redirect to Base URL' redirects all non-www pages to www home page on a multi-sit

SOLVED

Apparently, the trick is to place redirection code at the very beginning of the htaccess file!!

I have used the following code:

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

Re: PROBLEM: 'Auto-redirect to Base URL' redirects all non-www pages to www home page on a multi-sit

THANK YOU. I've spent 6h on this. Magento was redirecting to home page when auto redirect was on and the rewrite engine was not letting the .htaccess rewrites work, I was writing it at the end of the file. Writing redirect at the very beggining really do the trick.