Fix Laravel 404 Route Error (2025) – Apache & Nginx Guide

Fix Laravel 404 Route Error (2025) – Apache & Nginx Guide

🛑 Laravel 404 Route Not Found Error – Fix (2025)

One of the most frustrating issues in Laravel is when your routes don’t work and you see:

404 Not Found


Even though you defined routes in routes/web.php, the server can’t find them. Don’t worry — this is very common and easy to fix. ✅

🔍 Why Does This Error Happen?

Web Server Configuration Problem

Laravel routes go through public/index.php.

If your server doesn’t redirect requests properly, Laravel will show a 404.

Missing .htaccess (Apache)

If you are using Apache, .htaccess must exist inside the public/ folder.

Wrong Nginx Configuration

If you are using Nginx, you must configure try_files correctly.

🛠 Step-by-Step Fix
✅ 1. Apache Users – Check .htaccess

Inside your public/ folder, make sure you have this file:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>


👉 If it’s missing, copy it from the Laravel GitHub repo or a fresh Laravel installation.

✅ 2. Enable Apache Modules

Make sure mod_rewrite is enabled:

sudo a2enmod rewrite
sudo service apache2 restart


Also, update your Apache config (/etc/apache2/sites-available/000-default.conf) with:

<Directory /var/www/your-laravel-project/public>
AllowOverride All
Require all granted
</Directory>

✅ 3. Nginx Users – Update Config

If you’re using Nginx, open your server block config (/etc/nginx/sites-available/your-site):

server {
listen 80;
server_name yourdomain.com;
root /var/www/your-laravel-project/public;

index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}


👉 Save and restart Nginx:

sudo service nginx restart

✅ 4. Clear Laravel Cache

Sometimes old cache can cause route issues. Run:

php artisan route:clear
php artisan cache:clear
php artisan config:clear

🎯 Pro Tips

Always point your domain to the public/ folder, not the project root.

Check file permissions (storage and bootstrap/cache must be writable).

Use php artisan route:list to confirm that your routes are registered.

✅ Final Words

Most of the time, Laravel 404 errors are server config problems. Once you set .htaccess for Apache or try_files for Nginx, your routes will start working.

Back