Solved! Magento Admin Redirect Issue & 404

Magento 2 Admin Panel Redirect Issue

Note: If you are using StarFlare module for catalog search, before you change your Magento store URLs, stop Solr, start Elasticsearch, change your URLs, compile, and switch back. Then flush the config.

One of the most annoying aspects of caching and Magento’s FPC engine is sometimes you get an odd redirect when attempting to access the admin console. This can happen for many reasons, and the results are ususally Magento’s Admin console with a 404 or malformed URL.

Magento 2 Admin Panel Redirect Issue

You may get a URL that looks like this or just a 404.

Magento Admin URL 404 Solutions

If you are using Redis, try from the CLI:

sudo redis-cli flushall

Magento 2 Admin URL Reset

Sometimes your store URLs are not set correctly, or a rouge module makes a change that impacts your URLs.

First, reset your frontend admin URL:

sudo php bin/magento setup:config:set –backend-frontname=”{frontend value}”  #You can find the frontend in /apt/etc/env.php

sudo php bin/magento cache:flush config

Magento 2 Store URL Reset

Reset both legacy paths and new paths, plus reset your admin frontname. In our example, our domain name is with an admin frontname as admin_Demo .


sudo php bin/magento setup:store-config:set --base-url=""
sudo php bin/magento setup:store-config:set --base-url-secure=""

sudo php bin/magento config:set web/secure/base_url ""
sudo php bin/magento config:set web/secure/use_in_frontend ""
sudo php bin/magento setup:config:set --backend-frontname="admin_Demo"

Note: Use the trailing “/” and stay consistent with HTTP or HTTPS.

Run our compile script after you finish.

sudo ./

Cloudflare By-Pass Cache Page Rule

If you happen to be using Cloudflare, make sure you by-pass cache for your URL. Sometimes the static js causes issues.

You’ll have to play with this rule depending on how you have Magento configured. This example rule below is defined, because we use static on an S3 bucket via S3R-Alpha.