Solving Magento 2 Admin URL Issues: Reset your Admin Path
If you’re struggling to access your Magento 2 admin dashboard after changing the base URL from a custom path to a custom URL, don’t worryâyou’re not alone. This common issue can be resolved with some specific steps and a clear understanding of how Magento manages its admin paths.
Understanding the Problem: Mixed Admin Paths
The confusion likely arises because you’ve set both admin/url/custom (which uses a path like “admin_ad123”) and admin/url/use_custom_path (which expects an actual URL with a protocol, e.g., “https://example.com/admin_ad123”). This redundancy leads to Magento being unsure which admin link to follow.
Step 1: Identify the Culprit
First, let’s verify that the issue is indeed due to conflicting settings. You can check the current admin path using this command in your terminal:
bin/magento info:adminuri
This should return something like https://example.com/admin_ad123/.
Step 2: Clear Conflicting Settings
Next, we need to remove the conflicting settings from your database. You can do this directly via MySQL or by updating the core_config_data table manually.
Method 1: Update via MySQL
Connect to your Magento database and update the core_config_data table:
UPDATE core_config_data SET value = NULL WHERE path IN ('admin/url/custom', 'admin/url/use_custom');
This will remove the conflicting values for both fields.
Step 3: Update the Admin URL
Now, let’s set a new admin URL. You can do this either via the command line or directly in the database.
Method 1: Command Line
Use this command to set your new admin path:
bin/magento setup:config:set --backend-frontname="admin_new_path"
Replace “admin_new_path” with your desired admin URL prefix, like “admin_test”.
Method 2: Update via MySQL
Connect to your database and update the core_config_data table manually:
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', '0', 'admin/url/use_custom_path', 'https://example.com/admin_new_path');
Step 4: Flush Cache
After updating the settings, make sure to flush your cache:
bin/magento cache:flush
or if you have persistent caching enabled:
bin/magento cache:clean
Step 5: Verify the Change
Finally, try accessing your new admin URL. It should now take you directly to your Magento 2 admin dashboard.
Conclusion
Resolving this issue requires a systematic approachâclearing conflicting settings and updating the core_config_data table with the correct admin path information. Remember that Magento uses different fields for different types of admin paths, so it’s essential to set them correctly based on your needs.
If you found this guide helpful, consider checking out LaravelCompany’s other resources on Magento 2 development and e-commerce best practices. We’re committed to providing practical solutions for common challenges faced by developers like yourself.
Happy coding!