Redirect non-www to www on magento

Redirect non-www to www on magento

July 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Redirect non-www to www on magento

Redirect Non-WWW to WWW on Magento: A Comprehensive Guide

If you’re using Magento 1.9.1 and facing issues where all pages redirect to your homepage instead of the www version, don’t worry - you’ve come to the right place. In this comprehensive guide, we’ll walk you through the process of fixing this common problem.

Understanding the Issue: Why Pages Redirect to Homepage

The core issue lies in how Magento’s default .htaccess file handles redirects. By default, it rewrites all requests (except those for media, skin, and js folders) to index.php. This is why you’re seeing all pages redirecting to your homepage.

Fixing the Problem: Redirect Non-WWW to WWW

To solve this issue, we need to modify the .htaccess file located in your Magento root directory. Here’s a step-by-step guide:

  1. Backup Your Current .htaccess File Before making any changes, always backup your existing .htaccess file. This ensures you can revert to the original setup if something goes wrong.

  2. Open the .htaccess File in a Text Editor You’ll need access to the Magento root directory via FTP or SFTP. Open the .htaccess file using a plain text editor like Notepad, Sublime Text, or Visual Studio Code.

  3. Add the Following Lines Above the RewriteBase Line Copy and paste the following lines just above the line that starts with RewriteBase /shop/:

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

Replace mysite.ext with your actual domain name. This rule checks if the requested host is not using www, and if so, it redirects to the www version of your site.

  1. Save Your Changes Save the .htaccess file with these modifications.

  2. Clear Magento Cache After updating the .htaccess file, clear the Magento cache to ensure the changes take effect immediately:

    • Go to System > Cache Management
    • Select all checkboxes and click ‘Flush Magento Cache’
    • Click ‘Flush Cache Storage’

Verifying the Redirect

Now, try accessing your site using both www.mysite.ext and mysite.ext. You should notice that:

  • Accessing www.mysite.ext will keep you on the www version.
  • Accessing mysite.ext will redirect you to the www version.

Conclusion: Redirecting Non-WWW to WWW

Redirecting non-www requests to www is a best practice for several reasons, including SEO consistency and easier DNS management. By following this guide, you’ve successfully solved an issue that plagues many Magento users.

Remember, always backup your files before making changes, and don’t hesitate to contact us at Laravel Company if you need further assistance or have any questions about Magento development.

Happy coding!

Magento 1 Errors JavaScript

Our network