Today when I log in, my Magento admin URL shows a 404 error page. Please fix this.
That was a recent support ticket received at out Server Support department where we resolve support queries for web hosts.
Magento store owners face this error after installing or upgrading extensions, migrating websites, installing security patches, etc.
Today we’ll discuss the top 5 reasons for this error and how our Server Support Engineers fix it.
What is a 404 Error?
Simply put, 404 error means that the webpage doesn’t exist with the entered URL.
In other words, this is a generic HTTP error code, which indicates that the server can’t find the webpage requested by the user.
This means that either the page has been removed or broken.
Magento admin URL shows 404 error – Causes and Solutions
Based on our experience with Magento websites, we found a number of causes that turned out to be the culprit behind this error.
So, firstly we check the Magento logs such as exception.log and system.log and PHP error logs to find out where the problem originates.
Let’s now see why Magento admin URL shows 404 error and how our Support Engineers fix it.
1) Database inconsistencies
Ideally, in a Magento database, the store_id and website_id values for admin should be set to 0 (zero).
But, these values can change when store owners import the database to the new server, and users see 404 errors in Magento admin login page.
How we fix?
In this case, our Support Engineers correct the store_id and website_id for admin to 0 in the Magento database.
For example, we use the below command to update the website_id to 0 in the core_website table.
UPDATE 'core_website' SET website_id =0 WHERE code='admin';
Most importantly, we always backup the database before making any changes as a security measure.
After that, we refresh the Magento cache from System > Cache Management.
Alternatively, we remove the use_cache.ser file in the app/etc directory to clear the Magento cache settings.
2) Corrupted .htaccess file
Similarly, another common reason for this error is corrupted/missing .htaccess file.
The .htaccess file in Magento contains rewrite rules for the Magento site and associated links to work fine.
But, it can happen this file got accidentally deleted or modified by the website owners.
As a result, these rules no longer work and can result in 404 errors in Magento admin login page.
How we fix?
Our Support Engineers first check whether the .htaccess file is the actual culprit by temporarily renaming this file.
If any issues are noted, we will correct the misconfiguration in the .htaccess file.
And, if we find .htaccess file is missing, we download a fresh .htaccess file for the Magento application and upload it to the root folder.
[Messed up .htaccess rules in your website? Don’t worry, our Support experts are here to help you.]
3) mod_rewrite module disabled
Likewise, this problem can happen during fresh Magento installation.
Sometimes, the hosting server doesn’t support mod_rewrite module, and as a result users see 404 errors.
How we fix?
Our Support Specialists first check whether the mod_rewrite module is enabled on the server by checking the web server configuration file.
If it’s not enabled, we enable it and restart the web server to make the changes into effect.
For example, we uncomment the following line to enable mod_rewrite module in Apache web server.
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
In addition to that, we add the following code to the Apache configuration.
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
This allows any directives to be placed in the website user’s .htaccess file.
But, we always make sure to backup the Apache configuration file before making any changes, so if anything goes wrong, we can restore it back.
[And, do you want to enable this module on your server? Our Server Administration team can do this for you in minutes.]
4) Magento cache
Sometimes, Magento cache may also cause problems.
This happens mainly when store owners forget to clear the cache after applying security patches, installing or upgrading an extension.
As a result, the Magento admin panel shows old data.
How we fix?
Here, our Hosting Engineers clear the Magento cache from command line.
php bin/magento cache:clean
rm -rf var/cache/*
rm -rf var/generation/*
This clears the cache files and Magento starts showing the updated contents.
5) Custom admin URL
The default URL of Magento admin is “http://yourdomain.com/magento/admin“.
But, store owners have the privilege to customize it.
However, users run into problems, when changing the admin URL to a custom one, but don’t set the custom_admin_url settings properly.
How we fix?
In such cases, our Support Engineers will verify and correct the Magento admin URL in the following fields of core_config_data table.
- admin/url/use_custom
- admin/url/custom
- web/secure/base_url
- web/unsecure/base_url
Finally, we remove all cache files from var/cache folder.
Conclusion
In short, Magento admin URL shows 404 error due to database inconsistencies, cache issues, and more. Today, we’ve discussed the top 5 reasons for this error and how our Server Support Engineers fix it.
In my case, I had accidentally set a store as the default in the control panel.
In core_config_data:
layout_switcher/general/default_theme was set to ‘interiors’
Whenever I tried to access the admin area, I got the template for ‘interiors’ and a 404. To fix I set:
layout_switcher/general/default_theme back to ‘base’
I then ran:
php bin/magento cache:clean
php bin/magento cache:flush
Thanks for the tip Ben. 🙂