Magento 2 was just released last night and, I can't wait to work on it. I tried installing it with all prerequisites.

Frontend works fine. But when I tried to open the backend, it says "this webpage has a redirect loop". Magento created "admin_r2sxkn" as a unique backend URL. My Admin URL is http://localhost/magento2/admin_r2sxkn

As a solution, I tried deleting the cache which did not work.

P.S I have xampp on mac, with the latest versions of PHP and MySql, installed PHP extension incl as required.

Any help would be appreciated.

enter image description here

19 Answers 19


A browser does not support cookies on top-level domains like localhost. Please reinstall Magento on a different hostname (ex. magento.dev).

Also, Magento supports only Linux. So better to use Vagrant for development. You can use any exists preconfiguret vagrant instance that do all work for you


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.

  • This was my issue as well... Commented Jan 9, 2017 at 10:22
  • that is mail reason
    – Amit Bera
    Commented Mar 31, 2017 at 15:10
  • 1
    select * from core_config_data where path like "web/%";
    – david
    Commented Dec 9, 2017 at 21:21

Had redirect loop problem on Magento2 with a valid domain name after switching to https.

Check web/secure/use_in_adminhtml and web/secure/use_in_frontend settings in core_config_data, they both should be set to 1.

  • Thank you elene you saved our hell of a time. it worked for me. query to see values: select * from core_config_data where path like 'web/%'; Commented Feb 17, 2017 at 11:38
  • 1
    This was exactly what I needed. Also, if it's more convenient to do this from the command line rather than editing records in the database, it's magento config:set web/secure/use_in_adminhtml 1 and magento config:set web/secure/use_in_frontend 1
    – Colin
    Commented Jan 18, 2019 at 17:01
  • My hero! ;-) That was exactly what I needed. Commented Mar 27, 2020 at 8:08
  • 2
    There still one step left - to delete cach: rm -rf var/cache var/generation var/page_cache
    – ahgood
    Commented May 17, 2020 at 14:11

while installing magento2 on your localhost try to use in the your store address in step 3 instead of the localhost. now what can you do is in core_config_data table change following 2 rows

web/unsecure/base_url to
web/secure/base_url to

clear cache and check now


While installing try in the your store address in step 3 as shown in the screenshot

enter image description here

  • I made the same changes,magento2 admin now working with firefox but not with chrome, i also clear cache,but no result
    – Dinesh
    Commented Jan 21, 2016 at 9:47

I had a domain of the form local.abc_def.com and I was experiencing this issue.

I changed the underscore in the domain to be a hyphen, resulting in a domain of local.abc-def.com and this fixed the issue for me


Try to clean var/cache folder. It helps me.

  • +1 That was my issue too when trying to setup a live site on local,copied the var/cache folder by mistake.
    – Garry
    Commented Jun 11, 2023 at 9:02

Can be debugged in \Magento\Backend\Controller\Adminhtml\Auth\Login::execute

For example with

    $requestUrl = $this->getRequest()->getUri();
    $backendUrl = $this->getUrl('*');
    // redirect according to rewrite rule
    echo (string)$requestUrl . ' != ' . $backendUrl;

It is dies and the URLs are different, this give a hint to the problem.

  • I'm having almost the same problem as the OP but checking these vars just raises further questions - the two URLs never match, because the key is different on each, every time. If I try to load a URL without a key (just admin/ for example) it checks that against the URL with a key and redirects... to another URL with a key, which is checked against a URL which then has another different key??
    – James
    Commented Oct 3, 2018 at 9:18
  • Right, appears to be some bug/misconfiguration around using a custom admin URL - resetting this to 'admin' in env.php resolved the problem!
    – James
    Commented Oct 3, 2018 at 9:47

After switching http to https need to update following values in core_config_data table.

UPDATE core_config_data SET value = REPLACE(value, '0', '1') WHERE path = 'web/secure/use_in_frontend';

UPDATE core_config_data SET value = REPLACE(value, '0', '1') WHERE path = 'web/secure/use_in_adminhtml';

Then Clear caches and reload admin URL.

  • Why do you SET value = REPLACE(value, '0', '1') instead of SET value = '1'?
    – bfontaine
    Commented Sep 7, 2021 at 9:20

I've spent 8 hours on the topic, here are my conclusions

1) set AllowOverride all at apache directory configuration, at least to get .htaccess file to be readen, on the magento folder is the universal solution for getting the frontoffice && backoffice to work

2) set RewriteBase / in .htaccess or a subfolder if localhost/magento

3) Be sure to use https for the admin path in case those requests might proove handy ( otherwise the admin cookie won't set at all ) :


mysql -u a -pb -e "UPDATE magento.core_config_data SET value = 'https://$d/' WHERE path in('web/secure/base_url')";

mysql -u a -pb -e "UPDATE magento.core_config_data SET value=1 WHERE path in('web/secure/use_in_adminhtml')"

php bin/magento cache:flush

4) That's all, I've removed all the wrong guess from this post, as they were a lot in a first glance ..


Addiotionally to all the other answers, double check the URLs in your app/etc/env.php - they override configuration from the database:

'web' => [
    'unsecure' => [
        'base_url' => 'https://my.shop/',
    'secure' => [
        'base_url' => 'https://my.shop/',

If you use Varnish, do not forget to set:

RequestHeader set X-Forwarded-Proto "https"

in virtual host configuration.


I have a better solution to fix the above issue.

Open the .htaccess file

find the line

 #RewriteBase /magento/

According to your problem, Uncomment the line as

  RewriteBase /magento2/  

Note-: Save the .htaccess file Clean all the var/cache and browser cache.


Before installation, You must choose a valid domain name. For example: www.magento2-test.dev instead localhost. More details for this issue: here


Use localhost as an actual top level domain instead of standalone and you should be able to manage this. Using .dev is not a good idea as explained in this article: https://iyware.com/dont-use-dev-for-development/

http://magento.localhost/ would be suitable or if you have some DOMAIN.com that it will be deployed to later, you can do DOMAIN.localhost which later will end up at DOMAIN.com and then you can code your web server to look for the hostname regardless of TLD you use.

e.x. if you have two stores at DOMAIN1.com and DOMAIN2.com enter your rules in nginx conf (or whatever your web server of choice) as DOMAIN1.* for code evaluating DOMAIN1 specific code. Apache you might use something like SetEnvIf Host DOMAIN1\.(localhost|com)$ VAR=val in your .htaccess file.


In some scenarios deleting the cookies specific to the Magento2 installation and clearing Magento cache files in var/cache will resolve this problem.


You should delete var/cache/* and run setup:static-content:deploy command. it should be work. I solved this issue on my localhost with above step


Another thing to look out for is that your web server engine (nginx/apache) listens on SSL port 443 and that you have certificates configured. This was the issue for me together with advice already stated in other answers.


Try clearing cache bin/magento cache:clean


bin/magento cache:flush


This admin redirection loop can also occur if you've not setup the cookie domain properly in the admin, you can update it via admin in Store -> Configuration -> General -> Web -> Default Cookie setting -> Cookie Domain or using following cli command.

php bin/magento config:set web/cookie/cookie_domain your_top_level_domain

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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