Magento 2: Admin ERR_TOO_MANY_REDIRECTS

This article provides a solution to the redirect loop error while logging in to the Magento admin panel.

  • Did set up an existing Magento shop.
  • Went to the Magento admin login page
  • Entered admin username and password
  • Got the ERR_TOO_MANY_REDIRECTS error

The website has a redirect loop
ERR_TOO_MANY_REDIRECTS

Table of Contents

Cause

The problem is with the Cookie Domain for the Magento website.

i.e. the Magento configuration setting for web/cookie/cookie_domain

My Magento website domain was magento.test.
But, in the configuration settings, it was set as magento.host.

Solution

We need to update the configuration settings value for path web/cookie/cookie_domain with the correct cookie-domain name.

There are two ways to update the configuration settings values.

1) Update the configuration setting from the command line

Show the config value:

bin/magento config:show web/cookie/cookie_domain

Set the config value:

bin/magento config:set web/cookie/cookie_domain magento.test

2) Update database table rows

This one seems better as we can see the value for different stores/websites.

Check the values in the database table:

> SELECT * FROM core_config_data WHERE path LIKE '%web/cookie/cookie_domain%';
+-----------+---------+----------+--------------------------+------------------+---------------------+
| config_id | scope   | scope_id | path                     | value            | updated_at          |
+-----------+---------+----------+--------------------------+------------------+---------------------+
|        18 | default |        0 | web/cookie/cookie_domain | magento.host     | 2020-08-26 15:24:07 |
|      1033 | stores  |        3 | web/cookie/cookie_domain | ca.magento.test  | 2020-06-16 16:57:47 |
+-----------+---------+----------+--------------------------+------------------+---------------------+

Update the config setting value:

> UPDATE core_config_data SET value = 'magento.test' WHERE config_id = 18;

Clear Cache

bin/magento cache:flush

Now, you should be able to login to the Magento admin.

Hope this helps. Thanks.