Learn how to fix Laravel 404 errors using .htaccess on Apache. Enable mod_rewrite, configure AllowOverride, clear Laravel cache, and restore working routes with easy step by step instructions.
When a Laravel website opens the home page but every other page shows a 404 error, the issue is usually related to Apache rewrite rules or the server configuration. Laravel sends every request through the public/index.php file, so Apache must allow URL rewriting for routing to work correctly.
This guide explains the most common causes and the exact steps to get your Laravel routes working again.
Common Reasons for Laravel 404 Errors
A Laravel application may show 404 errors because of one or more of these reasons.
- Apache Rewrite Module is not enabled.
- The
.htaccessfile is missing or modified. AllowOverrideis not enabled in Apache.- The website points to the wrong document root.
- File and folder permissions need to be refreshed.
- Laravel route cache needs to be cleared.
Step 1: Verify Your Website Points to the Public Folder
The document root for your website should point to the public directory inside your Laravel project.
Example:
/var/www/laravel-app/public
Laravel is designed so that every web request starts from the public folder. Using the project root instead of the public directory prevents Laravel routing from working correctly.
Step 2: Check the Laravel .htaccess File
Open the .htaccess file inside the public folder.
cd /var/www/laravel-app/public
nano .htaccess
The default Laravel .htaccess file should look like this.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Save the file after confirming its contents.
Step 3: Enable the Apache Rewrite Module
Laravel routing depends on Apache's rewrite module.
Ubuntu and Debian:
sudo a2enmod rewrite
Restart Apache.
sudo systemctl restart apache2
Step 4: Enable AllowOverride
Open your Apache virtual host configuration.
Example:
sudo nano /etc/apache2/sites-available/000-default.conf
Locate the <Directory> section for your Laravel project and make sure it contains:
<Directory /var/www/laravel-app/public>
AllowOverride All
Require all granted
</Directory>
Save the file.
Restart Apache.
sudo systemctl restart apache2
Apache ignores .htaccess rewrite rules when AllowOverride is disabled.
Step 5: Clear Laravel Cache
After updating Apache or .htaccess, clear Laravel's cached files.
Go to your project directory.
cd /var/www/laravel-app
Run:
php artisan optimize:clear
You can also refresh the route cache.
php artisan route:clear
Refresh the configuration cache.
php artisan config:clear
Refresh the application cache.
php artisan cache:clear
Step 6: Check File Permissions
Make sure Apache can access the Laravel files.
sudo chown -R www-data:www-data /var/www/laravel-app
Set directory permissions.
sudo find /var/www/laravel-app -type d -exec chmod 755 {} \;
Set file permissions.
sudo find /var/www/laravel-app -type f -exec chmod 644 {} \;
Step 7: Verify Your Routes
List every registered Laravel route.
php artisan route:list
If your expected routes appear in the list, Laravel has loaded them successfully.
If a route is missing, check your routes/web.php or routes/api.php file and confirm the route has been defined correctly.
Step 8: Restart Apache
After making all changes, restart Apache once more.
sudo systemctl restart apache2
Open your browser and test several pages, such as:
https://example.com/
https://example.com/about
https://example.com/contact
All routes should load normally.
Troubleshooting Checklist
If the issue continues, verify the following items.
- The website document root points to the
publicfolder. - The
mod_rewritemodule is enabled. AllowOverride Allis configured.- The
.htaccessfile exists inside thepublicdirectory. - Laravel cache has been cleared.
- Routes are listed with
php artisan route:list. - Apache has been restarted after every configuration change.
Conclusion
Laravel 404 errors are usually resolved by confirming the Apache document root, enabling the rewrite module, allowing .htaccess rules, and clearing Laravel's cache. Once these settings are in place, Apache forwards every request to Laravel, allowing the framework to handle routing as intended.

