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.

http://192.168.29.156/admin_demo/http:/admin_demo/admin/index/index/key/70891b1fd78afeaa7cda1cd2caf873831789b15e90c9ae300f2a12f2cabf9538/

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 245.amistacxdemos.io with an admin frontname as admin_Demo .

Legacy:

sudo php bin/magento setup:store-config:set --base-url="https://245.amistacxdemos.io/"
sudo php bin/magento setup:store-config:set --base-url-secure="https://245.amistacxdemos.io/"

2.4.0+
sudo php bin/magento config:set web/secure/base_url "https://245.amistacxdemos.io/"
sudo php bin/magento config:set web/secure/use_in_frontend "https://245.amistacxdemos.io/"
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 ./amistacx.sh

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.

https://s3titanium.amistacxdemos.io/pub/static/adminhtml/

Lead_Robot