Magento redirects to base url using 302, how do I get it to use 301

Magento redirects to base url using 302, how do I get it to use 301

October 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento redirects to base url using 302, how do I get it to use 301

Magento Permanent Redirects: The Complete Guide

When managing an e-commerce site built on Magento, it’s crucial to ensure that your URLs are properly configured for SEO best practices. One common issue faced by many store owners is the default temporary (302) redirect from non-www versions of their site to the www version.

Understanding Magento URL Redirects

In Magento 1.x and earlier, URL redirects are managed through the System > Configuration > General > Web section’s Url Options. Here, you have a single setting: Redirect to Base URL if requested URL doesn’t match.

Setting this to ‘Yes’ enables redirects from non-matching URLs (like yourstore.com) to the base URL (www.yourstore.com). However, by default, Magento uses HTTP status code 302 for these redirects. This is not ideal from an SEO perspective because:

  1. 302 Redirects Are Temporary: Search engines treat them as temporary changes.
  2. SEO Impact: They don’t pass on link authority to the new URL.
  3. Crawl Optimization: Crawlers may retry fetching the old URLs, wasting resources.

Why You Need Permanent 301 Redirects

Implementing permanent redirects (301 status code) is essential for:

  • Telling search engines that a page has moved permanently.
  • Preserving link authority and SEO value of your site.
  • Preventing duplicate content issues.
  • Improving crawl efficiency.

How to Implement Permanent Magento URL Redirects

To change the redirect method from 302 to 301, you need to update your .htaccess file directly. Here’s a step-by-step guide:

Step 1: Backup Your Current .htaccess File

Before making any changes, always backup your current .htaccess file to prevent data loss.

Step 2: Locate the Rewrite Conditions

Open your current .htaccess file and locate the following conditions around line 30-35 (the exact position may vary):

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

Step 3: Add a New Condition for Non-WWW URLs

Add the following line below your existing conditions:

RewriteCond %{HTTP_HOST} ^yourstore\.com [NC]

Replace yourstore.com with your actual domain name.

Step 4: Change the Redirect Method

Update the last RewriteRule to use a permanent redirect flag:

RewriteRule ^(.*)$ http://www.yourstore.com/$1 [R=301,L]

Ensure that http://www.yourstore.com matches your base URL.

Step 5: Save and Test Your Changes

Save the .htaccess file and test it by accessing both the www and non-www versions of your site. You should now see a permanent redirect to the base URL.

Important Notes and Troubleshooting Tips

  1. Clear Cache: After making changes, clear your Magento cache from System > Cache Management for the updates to take effect.

  2. HTTP or HTTPS: Ensure that both your .htaccess file and the RewriteRule target match either HTTP or HTTPS exactly as used on your site.

  3. Testing: Use tools like Firebug’s Net panel or browser developer tools to verify that the redirects now use status code 301.

If you’re still having issues, double-check your configuration for any typos or mismatches in domain names and protocols.

Conclusion: The Importance of Permanent Magento Redirects

Implementing permanent redirect to base URL is a critical step in optimizing your Magento site’s SEO performance. It ensures that search engines understand your preferred domain structure, preserves link authority, and improves crawl efficiency.

Remember, the key lies in updating the .htaccess file directly—Magento’s admin interface only controls the flag for enabling or disabling redirects, not the method itself.

If you’re looking to hire professional Magento developers for more advanced customizations, I recommend checking out our dedicated Magento development services at Laravel Company.

Don’t let temporary redirects hold your e-commerce site back—go for a permanent solution today.

Magento 1 Performance Configuration SEO

Our network