32

I'm new to Magento, after installation of Magento 2 community edition.I am not able to access the admin panel. I am getting below error.

This web page has a redirect loop

Error ERR_TOO_MANY_REDIRECTS

Please help me to resolve the issue. Advance thanks to all.

4
  • Give more information. How did you install magento? What are the parameters, that you entered during installation Dec 22, 2015 at 14:58
  • Do you have XDebug enabled? Dec 22, 2015 at 15:12
  • After having some issues setting up SSL I got the same problem. Just running this fixed it: sudo php bin/magento cache:flush
    – AdNauseum
    May 2, 2019 at 22:49
  • Recommended solution !! This worked for me. It saved my time!. ERR_TOO_MANY_REDIRECTS
    – wewagod
    Mar 1, 2021 at 6:53

31 Answers 31

39

I had same problem manipulating databases, this answer resolved my problem ERR_TOO_MANY_REDIRECTS :

https://magento.stackexchange.com/a/84756/50635

To correct this, please try to set Use Secure URLs in Admin to true, in System -> Config -> General -> Web.

Or with database access, change following record value to 1 :

SELECT * FROM core_config_data where path like '%web/secure/use_in_adminhtml%';
6
  • 11
    In my case, it's value is already 1, still I'm seeing this error.
    – kashish
    Aug 18, 2017 at 7:53
  • 1
    works like charm
    – mrtuvn
    Mar 30, 2018 at 8:54
  • Works, very good Sep 26, 2018 at 8:45
  • 1
    surprised this got so many likes, the OP clearly stated "they" can't access the admin area so how are they suppose to go into the admin to change anything.
    – Sebastian
    Sep 4, 2020 at 11:44
  • 1
    Don't read the quote, but the text written in bold, you will be more surprised ;) Sep 5, 2020 at 13:50
36

In my case, I was importing an already existing Magento 2 database. The reason I was getting the error was because of the cookie domain in the database. Go to your database and look in the table core_config_data. You should see a path called web/cookie/cookie_domain. Make sure the domain matches the one you installed Magento 2 on. Ex: If you installed Magento 2 on local.dev/<magento-root> the entry in web/cookie/cookie_domain should be local.dev.

4
  • 8
    I was having the same problem. I changed the value in web/cookie/cookie_domain from NULL to my domain name, but still it's not working.
    – kashish
    Aug 18, 2017 at 7:51
  • 1
    Thanks a lot! I changed value to my "domain.local" and everything works Jan 11, 2019 at 14:46
  • thank you so much!! for me that was the issue! :D Dec 10, 2019 at 16:13
  • This only works if you import already used DB from live website. +1 May 28, 2021 at 5:39
22

I refer to your magento store domain as example.com in this post. If its www.example.com or store.example.com or whatever, substitute accordingly.

I just ran into this issue and here are the specifics. Magento 2 2.2.2 install. I had configured the secure base url's to http://example.com/ initially and as I was getting my letsencrypt ssl cert configured on my server, I thoughtlessly enabled the option to redirect all http traffic to https.

This wouldn't be an issue normally, but Magento can be a bit temperamental. I visited my storefront and my SSL is working correctly, but as I attempted to access admin, I received the "ERR_TOO_MANY_REDIRECTS" notice and a failed page load.

I see several ways to fix this issue but the one that worked for me first attempt was this.

  1. SSH into server.
  2. cd to your magento install dir.
  3. run the following command:
    • php bin/magento config:show

view the output and look for web/secure/base_url, web/secure/base_link_url & web/secure/use_in_adminhtml.

These values should be configured with https://example.com/ for the url options and web/secure/use_in_adminhtml = 1.

If they are not, you can run the following commands from your magento install directory to update your configuration.

  1. php bin/magento config:sensitive:set web/secure/base_url https://example.com/
  2. php bin/magento config:sensitive:set web/secure/base_link_url https://example.com
  3. php bin/magento config:set web/secure/use_in_adminhtml 1
  4. php bin/magento cache:clean

After that, visit your admin page, clear your browser cache, reload, and you should now have your access back! with SSL support.

First step I would take after that is to log back into the admin portal and verify your configuration options to ensure you arent going to run into any other unexpected problems.

I hope this help!

Here are some Magento resources to help guide you:

Set Configuration Values

Other Configuration Paths Reference

Sensitive and System Specific References

2
  • 1
    Thanks. Additionaly I had a redirect set up by plesk from http to https that I had to disable in order to get magento backend up. Note: cleaning cache is an important step here.
    – s.Daniel
    Mar 6, 2019 at 9:56
  • web/secure/base_url and web/secure/use_in_admin was not set for me. I was not able to run these command but I insert manually in database and it worked for me
    – Alam Zaib
    May 21, 2023 at 10:29
16

In my case, I copied website from client's server, and was setting up it on my local system. I simply removed cookie/domain from

core_config_data

table and then flushed cache, it worked for me!

You can also do it:

In the "core_config_data" table remove the value of "web/cookie/cookie_domain" and set "web/cookie/cookie_httponly" to "0". Clear the cache by removing the files in "var/cache".

9

Make sure that the cookie domain is set to your domain:

php bin/magento config:show web/cookie/cookie_domain

if not, then set it like this:

php bin/magento config:set web/cookie/cookie_domain www.example.com

I once noticed that the field with path web/secure/base_url was missing in the table core_config_data but web/unsecure/base_url existed. So I solved it by changing http in web/unsecure/base_url to https.

6

I had the same problem after switching the site to https. When I checked the web/cookie/cookie_domain in core_config_data it was NULL.

mysql> select * from core_config_data where path like 'web/cookie%';
+-----------+---------+----------+--------------------------+-------+
| config_id | scope   | scope_id | path                     | value |
+-----------+---------+----------+--------------------------+-------+
|        19 | default |        0 | web/cookie/cookie_domain | NULL  |
+-----------+---------+----------+--------------------------+-------+
1 row in set (0.00 sec)

I then set it to my fqdn:

mysql> update core_config_data set value = 'mysites.fqdn.com' where path = 'web/cookie/cookie_domain' ;

After that I restarted the website and it worked fine:

systemctl restart apache2
0
6

In my case problem was different.

SELECT * FROM core_config_data WHERE path = 'web/secure/offloader_header';

The value for this key should be X-Forwarded-Proto

On my server it was set as SSL_OFFLOADED (this is probably due to migration from Magento 1.9)

So I needed to change it back to the default Magento 2 value.

4

I spent 2 days fixing this issue. In my case I was using nginx reverse proxy proxy_pass magento 2.3 site hosted on apache2 virtual host. I tried to set all these configs:

  1. web/seo/use_rewrites -> 1 and 0
  2. web/unsecure/base_url -> http://.. and https://
  3. web/unsecure/base_link_url -> http://../ and https://../
  4. web/secure/base_url -> https://
  5. web/secure/use_in_frontend -> 1
  6. web/secure/use_in_adminhtml -> 1
  7. web/cookie/cookie_domain -> my.publicdomain.com
  8. web/cookie/cookie_httponly -> 1 and 0
  9. web/cookie/cookie_path -> /
  10. web/secure/base_link_url - https://../
  11. web/secure/base_static_url -> https://../
  12. web/secure/base_media_url -> https://../
  13. web/secure/enable_hsts -> 1 and 0
  14. web/secure/enable_upgrade_insecure -> 1 and 0

Playing with these configs using 1 or 0 values from http to https, but this issue didn't fixed even when deleted:

rm -rf pub/static/frontend/* pub/static/adminhtml/* var/cache/ generated/* var/page_cache/ var/view_preprocessed/ var/composer_home

And bin/magento setup:upgrade, bin/magento setup:di:compile, bin/magento setup:static-content:deploy -f

but all this didn't work...

TL;DR

Finally I came across this article: Magento 2 Full SSL with Varnish

And I changed my nginx virtual host config as below:

server {

        server_name magento2.local;

        location / {
                proxy_pass http://magento2.local:8765;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $http_host; # added this header
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto https; # added this header
                proxy_set_header X-Forwarded-Port 443; # added this header
        }


    listen 443 ssl http2; # here http2 was missing
    ssl_certificate /path_to_certificate.pem;
    ssl_certificate_key /path_to_certificate_key.pem;
    include /path_to/options-ssl-nginx.conf;
    ssl_dhparam /path_to/ssl-dhparams.pem;


}

and the config looks like this:

  1. web/seo/use_rewrites -> 1
  2. web/unsecure/base_url -> https://my.publicdomain.com/
  3. web/unsecure/base_link_url -> https://my.publicdomain.com/
  4. web/secure/base_url -> https://my.publicdomain.com/
  5. web/secure/use_in_frontend -> 1
  6. web/secure/use_in_adminhtml -> 1
  7. web/cookie/cookie_domain -> null
  8. web/cookie/cookie_httponly -> null
  9. web/cookie/cookie_path -> null
  10. web/secure/base_link_url - https://my.publicdomain.com/
  11. web/secure/base_static_url -> null
  12. web/secure/base_media_url -> null
  13. web/secure/enable_hsts -> 0
  14. web/secure/enable_upgrade_insecure -> 0

Cleared cache, setup upgraded deployed static files, cleared browser cache and boom admin got working again.

4

This worked for me !

php bin/magento config:set web/unsecure/base_url http://example.local/ 
php bin/magento config:set web/secure/base_url https://example.local/ 
php bin/magento config:set web/secure/use_in_adminhtml 1
1
  • 1
    Please don't edit in promotional links to your answers here. You are more than welcome to link to your stuff in your profile. Just don't do it in your posts. Oct 23, 2023 at 21:36
3

I got the error ERR_TOO_MANY_REDIRECTS because I forgot to set the PHP version to PHP7.

2

This error occurs due to using localhost as your hostname, especially in Chrome. We recommend using your own domain. Check Alan's blog for details

It is not Magento, it’s that web browsers behave differently when used with a domain name with less than 2 dots in it, such as localhost.

1
  • 1
    Where did OP mention he installed it using "localhost"?
    – MrUpsidown
    Mar 14, 2018 at 15:57
2

You can try reinstalling the Magento with your local IP rather than localhost.

This will be http://127.0.0.1/foldername. After installing this way, you will be able to access it from any browser.

You can also change the record in the database in core_config_data where the value will look like:

http://localhost/foldername/

replace that to

http://127.0.0.1/foldername/

In both ways, foldername is your directory where Magento resides.

2

Also - just to add what I experienced, if you are serving from apache but using nginx to terminate ssl (and probably varnish cache) then make sure your apache has

 SetEnvIf X-Forwarded-Proto "https" HTTPS=on

otherwise it goes around and around with nginx redirect frenzy

2

None of the proposed solutions here worked for my development environment that was running in a Docker container. What worked for me was changing the following line in etc/nginx/fastcgi:

fastcgi_param HTTPS $https if_not_empty;

…to:

fastcgi_param HTTPS on;

Source: https://magenticians.com/magento-ssl-configuration-issues-resolved/#Enabling-SSL.

2
  • (Don’t forget to restart the container after making said changes.)
    – ACJ
    Jul 17, 2019 at 8:58
  • 1
    Thanks so much! This worked for me. None of the other answers work. Mar 29, 2021 at 9:55
2

This works for me.

Place a new copy of .htaccess from a fresh Magento package and delete the cache and session folder as well. Then refresh and it should be good.

Or another way is, ( Setting up the database )

In the “core_config_data” table remove the value of “web/cookie/cookie_domain” and set “web/cookie/cookie_httponly” to “0”. ( rm -rf var/cache )Clear the cache by removing the files in “var/cache”.

1

Resolving this problem https://github.com/magento/magento2/issues/2473 you need to change the name of the domain name

0

Don't use umlauts in base-url e.g.:

www.yourhost/österreich

I had to rename it to

0

In my case, I have set the value for the web/cookie/cookie_domain path in the core_config_data table to NULL.

You can do that using Magerun, like that:

magerun config:set web/cookie/cookie_domain NULL
0

In my case I was using IP instead of localhost but still didn't resolve. Changed admin url key. It worked.

Of course all above answers are still valid as we faced and applied those during development.

Chrome causes this a lot. Firefox is bit better in handling this.

0

I am using Magento 2 on AWS and by following Ryan Wilson's suggestion Fixed the problem by going to the htdocs folder where magento is installed and use the following command

sudo php bin/magento config:set web/unsecure/base_url http://www.yoursite.com/
sudo php bin/magento config:set web/secure/base_url https://www.yoursite.com/
php bin/magento cache:clean
0

in version magento 2.2 I coulnd't even find web/cookie/cookie_domain path in the core_config_data. so in my case the problem was with memcached service. I have set up session.save_handler = memcached in php.ini according to magento docs and this stopped admin from opening correctly, meanwhile front was ok. After changing handlers back to session.save_handler = files all worked

0

i had same problem get it fixed by going in

SELECT * FROM core_config_data where path like 'web/secure/use_in_adminhtml'

the valued is changed by NULL to 1

0

Manually delete var/cache/* and var/sessions/* did fixed for me after moving the site from one sub domain to another and changing the necessary base_urls.

0

In my case Windows did not produce the interceptors properly. I compiled the code on my windows OS and copied the code into my docker container. I suggest the problem is a path issue. See here

My Magento Version was 2.3.3

0

Try below command and it should work,

php bin/magento config:set web/secure/use_in_adminhtml 1
0

Magento is redirecting to defined urls in the settings and also it tries to redirect to secure url if not allowed in config. In the proposed solutions are all other causes covered.

In our cause it has been a docker container running magento behind Apache proxy and when we configured the Magento to public url we got redirect loop. The fix was to add to configuration

# Redirect all requests to their respective HTTP vhosts
    RewriteEngine On
    RewriteRule ^/(.*) http://docker.example.com:8011/$1 [P]
    ProxyPassReverse / http://docker.example.com:8011/

## This fixed the redirect loop
    ProxyPreserveHost On # otherwise the Magento will receive http://docker.example.com:8011 as current url
    RequestHeader set X-Forwarded-Proto "https"  # this tells the magento this coneection is HTTPS

To summarise.

  • check you have set correct urls. But I am not sure about that 1. You may try 0
php bin/magento config:set web/unsecure/base_url http://example.local/ 
php bin/magento config:set web/secure/base_url https://example.local/ 
php bin/magento config:set web/secure/use_in_adminhtml 1
php bin/magento cache:flush
  • check the proxy settings if you run on the docker behind proxy (above solution)
  • check the cookie domain (it is probably not the cause, if you have more store URLs then it may be issue I think. It is not usually set.)
php bin/magento config:set web/cookie/cookie_domain www.example.com

After any configuration change don't forget to flush cache.

php bin/magento cache:flush
0

Maybe you set a secure url as http instead of https.

If you are using true on %web/secure/use_in_adminhtml

SELECT * FROM core_config_data where path like '%web/secure/use_in_adminhtml%';
+-----------+---------+----------+-----------------------------+-------+
| config_id | scope   | scope_id | path                        | value |
+-----------+---------+----------+-----------------------------+-------+
|         6 | default |        0 | web/secure/use_in_adminhtml | 1     |
+-----------+---------+----------+-----------------------------+-------+

you'll need to as https your urls into your core_config data.

Double check the

`SELECT * FROM `core_config_data` WHERE `path` LIKE '%web%`;
0

add this to nginx config file

fastcgi_param  HTTPS "on";
fastcgi_param  HTTP_X_FORWARDED_PROTO "https";

so final code will look like this

# PHP entry point for main application
location ~ (index|get|static|report|404|503)\.php$ {
try_files $uri =404;
fastcgi_pass   fastcgi_backend;
fastcgi_buffers 1024 4k;

fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;

fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  HTTPS "on";
fastcgi_param  HTTP_X_FORWARDED_PROTO "https";
include        fastcgi_params;

}

0

It might be possible, that you are trying to log into a new created admin user account (with a different user role) and forget to set the role resources.

-1

Please check if in your nginx/apache there is SSL connection configured. Once you ticked SSL connection for admin access and you do not have SSL configured, it redirects to standard http:// connection and then back to https://. That's why there is a loop.

There should be something like this in nginx:

server {
    listen 80;
    listen 443 ssl;
    server_name test.com;
    set $MAGE_ROOT /storage/test.com;
...
1
  • Where did OP mention nginx? Where did you change that configuration and why? What does it do?
    – MrUpsidown
    Mar 14, 2018 at 16:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.