How to redirect Magento from Non www to www use .htaccess

Written by Administrator LAST UPDATED | 30 November 1999
Rate this item
(2 votes)

Several times we have received above question from our customer in order that to day we will show you how to redirect your Magento site from a non-www, ex. http://yoursite.com to http://www.yoursite.com. There is a trick there.

  1. Enable Url rewriting (Admin Panel → System → Configuration → Web → Url Options → Use Web Server Rewrites → Yes).
  2. Now go to your .htaccess file on your Magento folder, (you might need to back up your .htaccess before making your changes.)

below the line # 123 code:

#RewriteBase /magento/

Add these codes, to make it:

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

Replace yoursite.com with your own domain. Then, save your changes on your .htaccess

back to top