Magento 301 redirect from non-www to www

Posted by Damodar Bashyal on April 12, 2012

 

Magento by default doesn't use 301 permanent redirection when redirecting website from non-www to www or www to non-www. It instead uses 302 temporary move. If you are looking for SEO benefit or get higher rankings on google, always use www or non-www version of your website otherwise your website will be penalize by google search engine, bing search engine and others as well.

So, how can you configure your website to use 301 permanent redirect instead of 302 temporary move?

If you follow steps below you will be all set and start getting ranking better on google.

301 Redirection Option 1:

  1. Log into your Magento admin.
  2. Go to 'System' from the top menu on right corner.
  3. Then click on 'Configuration' under sub menu.
  4. After configuration page loads, look for 'Web' under General on the left hand sidebar.
  5. Expand URL options.
  6. Here change Auto-redirect to Base URL option from "Yes (302 Found)" to "Yes (301 Moved Permanently)".

Now load your website without www, it should redirect your website to www and vice versa if you are using otherway around.

301 Redirection Option 2:

You can also use .htaccess to achieve above result. i.e. 301 redirect.

Open your .htaccess file and on the very top add this:

<IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteCond %{HTTPS} !=on
     RewriteCond %{HTTP_HOST} !^www\. [NC]
     RewriteCond %{SERVER_ADDR} !=127.0.0.1
     RewriteCond %{SERVER_ADDR} !=::1
     RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
 
not published on website


QR Code: Magento 301 redirect from non-www to www