Learn how to fix Apache 404 errors after migrating your website. Check DocumentRoot, .htaccess, mod_rewrite, permissions, and Apache configuration step by step.
Moving an Apache website to a new server is usually a smooth process, but sometimes every page except the homepage starts showing a 404 Not Found error. This happens because the new server may be using different Apache settings, a different document root, or missing modules.
The good news is that this is usually a quick fix. This guide walks through the most common causes and shows you how to get your website working again.
Common Reasons for 404 Errors After Migration
A website migration can introduce one or more of these issues:
- The website files were copied to the wrong directory.
- The Apache Virtual Host uses the wrong
DocumentRoot. - The
.htaccessfile was not copied. - The Apache rewrite module is not enabled.
AllowOverrideis disabled.- File and folder permissions need to be updated.
- Apache configuration changes have not been reloaded.
Go through the steps below one by one.
Step 1: Check the Website Files
First, make sure your website files are actually in the correct directory.
For Ubuntu and Debian systems, the default web directory is usually:
cd /var/www/
ls -la
If your website uses a custom directory, go there instead.
For example:
cd /var/www/example.com/public_html
ls -la
Make sure important files such as index.php, index.html, or your application files are present.
Step 2: Verify the Apache DocumentRoot
After migration, Apache may still be pointing to the old location.
Open your Virtual Host configuration.
sudo nano /etc/apache2/sites-available/000-default.conf
Or, if you use a custom virtual host:
sudo nano /etc/apache2/sites-available/example.com.conf
Check that the DocumentRoot points to the correct website directory.
Example:
DocumentRoot /var/www/example.com/public_html
Save the file after making any changes.
Apache uses the DocumentRoot directive to determine where your website files are located. If this path is incorrect, Apache will return 404 errors because it cannot find the requested pages.
Step 3: Make Sure the Website Configuration is Enabled
List all enabled websites.
ls -l /etc/apache2/sites-enabled/
If your website is not enabled, run:
sudo a2ensite example.com.conf
Reload Apache.
sudo systemctl reload apache2
Step 4: Enable the Apache Rewrite Module
Many PHP applications such as WordPress, Laravel, CodeIgniter, and custom frameworks rely on the rewrite module.
Check whether it is enabled.
apache2ctl -M | grep rewrite
If nothing is returned, enable it.
sudo a2enmod rewrite
Restart Apache.
sudo systemctl restart apache2
Apache processes rewrite rules only when the rewrite module is loaded.
Step 5: Allow Apache to Read the .htaccess File
A very common reason for 404 errors after migration is that Apache is ignoring the .htaccess file.
Open your Virtual Host configuration.
sudo nano /etc/apache2/sites-available/example.com.conf
Inside the <Directory> block, make sure it looks similar to this:
<Directory /var/www/example.com/public_html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save the file.
Restart Apache.
sudo systemctl restart apache2
Apache only reads rewrite rules from .htaccess when AllowOverride permits them. Without this setting, friendly URLs often return 404 errors.
Step 6: Confirm the .htaccess File Exists
Go to your website directory.
cd /var/www/example.com/public_html
Show hidden files.
ls -la
You should see:
.htaccess
If the file is missing, copy it from your previous server or restore it from your backup.
Many applications store rewrite rules inside this file.
Step 7: Check File Permissions
Apache must be able to read your website files.
Update ownership.
sudo chown -R www-data:www-data /var/www/example.com/public_html
Set folder permissions.
sudo find /var/www/example.com/public_html -type d -exec chmod 755 {} \;
Set file permissions.
sudo find /var/www/example.com/public_html -type f -exec chmod 644 {} \;
Step 8: Test the Apache Configuration
Before restarting Apache, verify that the configuration is valid.
sudo apache2ctl configtest
A successful result looks like this:
Syntax OK
If everything is correct, reload Apache.
sudo systemctl reload apache2
Testing the configuration before reloading helps catch syntax mistakes early.
Step 9: Check the Apache Error Log
If the problem continues, review the Apache error log.
On Ubuntu and Debian:
sudo tail -f /var/log/apache2/error.log
Open your website in a browser while watching the log.
The log usually points directly to the missing file or configuration issue.
Quick Checklist
Before testing your website again, make sure all of these are complete:
- Website files are in the correct directory.
DocumentRootpoints to the correct location.- The website Virtual Host is enabled.
mod_rewriteis enabled.AllowOverride Allis configured.- The
.htaccessfile exists. - File permissions are correct.
- Apache configuration passes
configtest. - Apache has been reloaded or restarted.
Conclusion
Most Apache 404 errors after a website migration are caused by an incorrect DocumentRoot, a missing .htaccess file, the rewrite module not being enabled, or AllowOverride preventing Apache from reading rewrite rules. Once these settings are verified and Apache is reloaded, your website URLs should work as expected.
Taking a few minutes to review the Apache configuration after every migration helps ensure your website is available immediately on the new server.

