'Magento2 : Admin redirection issue

I have installed Magento2 on my WAMP server. And when I tried to access http://127.0.0.1/magento2/admin/ it's redirecting to http://localhost/admin/admin/dashboard/ (An invalid URL)?



Solution 1:[1]

the file app/etc/env.php should start like this.. check your backend frontName :)

<?php
return array (
  'backend' => 
  array (
    'frontName' => 'admin_xu4zwa'
  ),
);

Solution 2:[2]

I think your magento installation foldername and value in table core_config_data field "base_url" is not same.

  1. In terminal run command: php bin/magento info:adminuri , say it shows: admin_mkp
  2. In database run sql: SELECT * FROM core_config_data WHERE (scope LIKE '%_url%' OR path LIKE '%_url%' OR value LIKE '%_url%') LIMIT 50
  3. Check value of web/unsecure/base_url say value is: http://127.0.0.1/magentoxyzfoldername/
  4. Now your adminurl should be like this: http://127.0.0.1/magentoxyzfoldername/admin_mkp

note: magentoxyzfoldername is your magento installation folder name.

Solution 3:[3]

We can also check the admin url by using command

        $ php bin/magento info:adminuri

Solution 4:[4]

You need to check the following

  • Check Your admin backend name
  • make sure you have mod_rewrite enabled in apache
  • Make sure you have installed magento properly if not try to reinstall it.

Solution 5:[5]

change the base_url value in table core_config_data to http://127.0.0.1/magento2/ instead of http://localhost/magento2/, you can find the record in the table using SELECT * FROM core_config_data WHERE path='web/unsecure/base_url';.

Solution 6:[6]

change base url from core_config_data table and check frontName in app/etc/env.php file. Hope, this will help.

Solution 7:[7]

After installation of Magento2 site into a new location, you need to run all magento commands, after changing url in core_config_data table and changing connection in app/etc/env.php file.

php bin/magento setup:di:compile
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Solution 8:[8]

I think you need to set web/unsecure/base_url and web/secure/base_url in core_config_data table with your url like : http://127.0.0.1/magento2/

Or you can set this setting from admin side Stores > Configuration > General > Web:
Base Urls

Base URL : http://127.0.0.1/magento2/

Base Urls (Secure)

Base URL : https://127.0.0.1/magento2/

Solution 9:[9]

I hope it will works!

First you can check the file app/etc/env.php and check backend frontName should be 'admin' like below.

return [
    'backend' => [
        'frontName' => 'admin'
    ],
   ...........
   ...........
   ...........
];

And then run this command

php bin/magento setup:di:compile
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Solution 10:[10]

try switch to Developer mode

bin/magento deploy:mode:set developer

Solution 11:[11]

Check your base_url on database core_config_data table
And also check app/etc/env.php frontName value.
After that:

set module:developer
setup:upgrade
clean cache

Solution 12:[12]

Open Mysql and run below mysql query:

UPDATE `core_config_data` set value = "http://127.0.0.1/magento2/admin/" WHERE path like "%base_url"

After run Mysql query you need to run below command in ssh terminal for flush cache or you can direct delete magento root var/cache folder. After that try to open magento admin it would work.

php bin/magento cache:flush

Solution 13:[13]

need to enter host entry for local

sudo nano /etc/apache2/sites-available/000-default.conf

Add the path to your Magento pub/ directory to the DocumentRoot directive

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/magento2/pub
         ServerName hostname.magento.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html">
AllowOverride all
</Directory>
</VirtualHost>

sudo systemctl restart apache2