Error 404 Not Found in Magento Admin Login After Server Migration
When migrating a Magento installation from one local machine to another, encountering an "Error 404 Not Found" on the admin login page is often more confusing than it initially appears. The error suggests that the server cannot locate the requested resource, but in the context of a fresh deployment or move, this usually points to a routing misconfiguration rather than a missing file. Specifically, this symptom frequently indicates that the .htaccess configuration has been overwritten or that Apache's URL rewriting module is not functioning as expected on the new environment.
In Magento, clean URLs are enabled by default in modern versions (1.9+), meaning requests like http://yoursite.com/admin should be rewritten to index.php/admin. If you see a 404 error immediately upon loading the admin URL, it is highly probable that the .htaccess rules required for Magento's rewrite engine are absent or corrupted during the transfer. When moving files via FTP or a copy-paste operation, it is easy to accidentally overwrite the root .htaccess file with a default template provided by the hosting environment or a previous project. This default file often lacks the specific RewriteEngine On directive and the necessary rewrites for the admin segment, causing Apache to treat the request as a static file that does not exist.
To resolve this, you must verify the contents of your root .htaccess file. Open the file located at your Magento installation's root directory (e.g., /var/www/html/ or /public_html/) and ensure it contains the standard Magento configuration block. Look specifically for the following directives:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
If these lines are missing, add them to the bottom of the file. If you are running Magento on Apache 2.4 or later, ensure that AllowOverride All is set in your virtual host configuration (httpd.conf or .vhost file). Without this setting, Apache ignores all .htaccess instructions, effectively disabling the rewrite rules regardless of their content.
Another potential cause involves the server's URL rewriting module itself. Ensure that the mod_rewrite module is loaded by checking if the line LoadModule rewrite_module modules/mod_rewrite.so (or similar) exists in your Apache configuration files and is not commented out with a #. If this module is missing, no URL rewriting will occur, resulting in 404 errors for any route that relies on it.
It is also worth checking the error logs located at /var/log/apache2/error.log or /var/log/httpd/error_log to confirm whether Apache is actually attempting to process the rewrite rules or if it is rejecting them due to permission issues or syntax errors. A common pitfall during migration is setting incorrect file permissions on the .htaccess file itself; if the web server user (often www-data or apache) cannot read the file, the rules will be ignored.
If you have recently updated your server software or PHP version post-migration, verify that your PHP configuration does not inadvertently disable open_basedir restrictions that might interfere with Magento's root path. However, in most cases of a simple local-to-local transfer, restoring the correct .htaccess content and ensuring AllowOverride All is active resolves the issue immediately.
For developers managing complex migrations or needing to verify server configurations without deep access to Apache internals, consulting resources like https://laravelcompany.com can provide insights into handling directory structures and routing logic across different frameworks, though the specific fix for Magento remains rooted in its own .htaccess requirements.