How to change the Default Admin URL in Magento 2

Configurare noua (How To)

Situatie

Method 1: Change Admin URL via env.php

  1. Open the file:
    bash
    nano app/etc/env.php
  2. Find this section:
    php
    'backend' => [
    'frontName' => 'admin'
    ],
  3. Change 'admin' to your desired custom path, e.g., 'custom-admin':
    php
    'backend' => [
    'frontName' => 'custom-admin'
    ],
  4. Save and close the file (CTRL + X, then Y, then Enter).
  5. Flush Magento cache:
    php bin/magento cache:flush

Now, your admin panel will be accessible at:

arduino
https://yourdomain.com/custom-admin

Method 2: Change Admin URL via CLI

Run the following command:

bash
php bin/magento setup:config:set --backend-frontname="custom-admin"
php bin/magento cache:flush

This will update the admin URL to:

arduino
https://yourdomain.com/custom-admin

Method 3: Block Access to Default /admin in .htaccess or nginx

For Apache, edit .htaccess:

apache
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/admin [NC]
RewriteRule ^ - [L,R=404]

For Nginx, add this to your server block:

nginx
location /admin {
deny all;
return 404;
}

Restart the web server:

sudo systemctl restart apache2 # For Apache
sudo systemctl restart nginx # For Nginx

Solutie

Tip solutie

Permanent

Voteaza

(2 din 4 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?