You fire up your local Magento 2 installation, excited to get some work done, and… BAM! Instead of your store, you’re met with an endless “Too Many Redirects” error. Your browser keeps bouncing back and forth between URLs like a confused courier, and your site just won’t load. Frustrating, right?
This issue is surprisingly common in local Magento environments, especially if you’re using custom domains, HTTPS, or a misconfigured web server. Magento relies heavily on proper URL handling, and a small misconfiguration can send it spiraling into an infinite redirection loop.
But fear not! 🦸♂️ In this blog post, we’ll break down exactly why this happens and guide you through the step-by-step fixes to get your local Magento back to working order. No more infinite loops, just smooth sailing! 🚀
Let’s dive in and get your Magento back on track. 🛠️
Why Is This Happening?
The “Too Many Redirects” error is usually caused by a misconfiguration in your Magento base URLs, secure settings, or the way Magento detects HTTPS. Since Magento heavily relies on URL structure, incorrect settings can send your site into an infinite redirection loop between HTTP and HTTPS.
Some of the most common causes include:
Incorrect Base URLs (Your site might be forcing HTTP while your browser expects HTTPS)Misconfigured web/secure/offloader_header Setting (Magento doesn’t recognize SSL from a reverse proxy)Conflicting Apache/Nginx Rewrite RulesCookies or Cache Issues
Let’s fix this once and for all!
Step 1: Check and Correct Magento Base URLs
Your first stop should be to ensure that Magento’s base URLs are set correctly.
How to Check and Fix Your Base URLs
You can do this via the Magento CLI or directly in the database.
Method 1: Using Magento CLI
Run the following command to check your base URLs:
bin/magento config:show web/unsecure/base_url
bin/magento config:show web/secure/base_url
If the values are incorrect, update them:
bin/magento config:set web/unsecure/base_url http://mylocalmagento.test/
bin/magento config:set web/secure/base_url https://mylocalmagento.test/
Then, flush the cache:
bin/magento cache:flush
💡 Pro Tip: Make sure your local domain matches the one in your browser (e.g., http://localhost/ vs http://mylocalmagento.test/).
Method 2: Fixing via MySQL
If you can’t access the CLI, update the Magento database directly.
Run this SQL command:
UPDATE core_config_data
SET value = 'http://mylocalmagento.test/'
WHERE path = 'web/unsecure/base_url';
UPDATE core_config_data
SET value = 'https://mylocalmagento.test/'
WHERE path = 'web/secure/base_url';
DELETE FROM cache_config;
Then, restart your web server (Apache/Nginx) and clear the cache:
bin/magento cache:flush
Now, refresh your browser and check if the issue is resolved.
Step 2: Fix the Offloader Header (For HTTPS Issues)
If your local environment uses HTTPS through a reverse proxy (like Docker, Traefik, or Nginx), Magento might not be detecting it correctly. That’s where the offloader header comes in.
How to Set web/secure/offloader_header Properly
Run this command to set the correct header:
bin/magento config:set web/secure/offloader_header X-Forwarded-Proto
Then, flush the cache and restart your Magento instance:
bin/magento cache:flush
💡 Why is this important? If Magento doesn’t recognize SSL, it might keep redirecting between HTTP and HTTPS endlessly, causing the too many redirects error.
Step 3: Check and Fix Your Web Server Configuration
Your web server (Apache or Nginx) might have redirect rules conflicting with Magento’s settings. Let’s check them.
For Apache Users
Open your .htaccess file and check if there are duplicate redirect rules:
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If your Magento base URL is already set to HTTPS, this rule may not be necessary—try commenting it out and restarting Apache:
# RewriteCond %{HTTPS} off
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Restart Apache:
sudo service apache2 restart
For Nginx Users
Open your Nginx configuration file (/etc/nginx/sites-available/default or similar) and check for duplicate redirect rules:
server {
listen 80;
server_name mylocalmagento.test;
return 301 https://$host$request_uri;
}
If Magento is already handling HTTPS, this extra redirect can cause a loop. Try disabling it and restarting Nginx:
sudo service nginx restart
Step 4: Clear Your Browser Cache and Cookies
Still seeing the “Too Many Redirects” error? Your browser might be caching old redirects.
Try this:
- Open the site in incognito mode 🕵️♂️
- Clear cookies and site data for your local Magento domain
- Try a different browser
If the error disappears, it was a browser caching issue!
Step 5: Flush Magento Cache and Sessions
Magento caches URL redirects and session cookies. If all else fails, try this:
bin/magento cache:clean
bin/magento cache:flush
bin/magento indexer:reindex
rm -rf var/session/*
rm -rf var/cache/*
rm -rf var/generation/*
rm -rf pub/static/*
And restart your local server:
sudo service apache2 restart # For Apache
sudo service nginx restart # For Nginx
Now, reload your site. Did it work? High five! 🙌
Final Thoughts: Keep Your Local Magento Healthy!
If your Magento local installation ever decides to go into redirect loop madness, now you know how to bring it back to sanity. 🎉
✅ Check Base URLs
✅ Fix offloader_header Issues
✅ Review Apache/Nginx Redirects
✅ Clear Browser Cache & Magento Cache
This guide should help you resolve the “Too Many Redirects” error and prevent it from happening again. Got another Magento mystery? Drop a comment! 🚀
Pingback: Understanding Magento 2’s web/secure/offloader_header: Your Fix for Redirect Chaos – Tiago Sampaio