How to Fix 404 Not Found on All Routes After Deploying Laravel to Subfolder
You upload your Laravel project to a subfolder like: public_html/myapp/ or example.com/projects/laravel-app Locally everything works, but on the server every route returns: 404 Not Found even for /, /login, or /home. That usually means the web server isn’t pointing to Laravel’s public folder correctly, or the rewrite rules don’t match the subfolder path.
Let’s fix it step by step.
1. Understand your real URL and folder
Common subfolder setups:
- Files live in:
/public_html/myapp
URL:https://example.com/myapp - Files live in:
/var/www/html/project
URL:https://example.com/project
Inside that folder you still have Laravel’s structure:
myapp/
app/
bootstrap/
public/
routes/
vendor/
The important bit is: the web server must serve from /myapp/public, not from the project root directly.
2. Fix the document root (preferred solution)
The cleanest approach: point the site or subdomain directly to Laravel’s public folder.
In your hosting panel or vhost config:
- Document root:
/public_html/myapp/public
Nginx example:
root /var/www/html/myapp/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Apache example (vhost):
DocumentRoot /home/user/public_html/myapp/public
<Directory /home/user/public_html/myapp/public>
AllowOverride All
Require all granted
</Directory>
If the document root points to myapp instead of myapp/public, Laravel’s index.php is never hit correctly and you get 404s or static file listings.
3. If you must keep Laravel in a subfolder URL
Sometimes you don’t control vhosts and you must run from a URL like:
https://example.com/myapp
with document root /public_html.
In that case:
- Put Laravel project outside
public_html, for example:/home/user/laravel-app /home/user/public_html/myapp (contains only public files) - Copy the content of Laravel’s
publicfolder into/public_html/myapp(index.php, .htaccess, etc.). - Edit
index.phppaths to point to the real app folder:require __DIR__.'/../../laravel-app/vendor/autoload.php'; $app = require_once __DIR__.'/../../laravel-app/bootstrap/app.php'; - Make sure
.htaccessin/public_html/myappuses the subfolder correctly (next section).
4. Update .htaccess for subfolder routing (Apache)
If you’re using Apache and every route is 404, your .htaccess might be missing or incorrect.
Inside the public (or myapp) folder, you should have:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /myapp/ # important when app is in a subfolder
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If your app is at the domain root, RewriteBase / is enough.
For a subfolder like /project/, change it to /project/.
Without the correct RewriteBase, Apache may not send the requests to index.php, so Laravel routes are never hit.
5. Set APP_URL to the subfolder URL
In .env:
APP_URL=https://example.com/myapp
This doesn’t directly cause 404s, but if APP_URL is wrong, generated URLs, redirects, and asset links may point to the wrong place and appear broken.
After changing it, clear config:
php artisan config:clear
6. Check that mod_rewrite (Apache) or try_files (Nginx) is enabled
For Apache:
mod_rewritemust be enabled.- AllowOverride must be set to
Allfor the public folder.
If .htaccess is ignored, routes will 404.
For Nginx, inside the server block:
location /myapp/ {
alias /var/www/html/myapp/public/;
try_files $uri $uri/ /myapp/index.php?$query_string;
}
Note the combination of alias and try_files to make Laravel handle internal routes.
7. Quick checklist for 404 after subfolder deploy
- Document root points to
project/public(or subfolder version of it). .htaccessexists in public folder with correctRewriteBase.- APP_URL uses real URL (
https://example.com/myapp). - mod_rewrite enabled (Apache) or try_files configured (Nginx).
- No old index.php or .htaccess in parent folders overriding Laravel.
Once the web server actually sends all unknown requests to public/index.php, your Laravel routes will resolve correctly even when the project is deployed to a subfolder.