Skip to content
PHP and Laravel3 min read

Laravel home page works but every other route returns 404

404 Not Found (every route except /)

Short answer

If the Laravel home page works and every other route gives 404, the server is not passing requests to index.php. Most often the .htaccess file in the public folder was never uploaded because it is hidden. Try example.com/index.php/login: if it works, the problem is .htaccess; if not, it is how the routes are defined or cached.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Who is returning the 404?
  2. Causes, most likely first
  3. How to confirm it is fixed
  4. How to avoid it
  5. On ArabyHost

The home page loads fine, but /login, /products and every other URL give a 404 error. Before opening your route files, look at the 404 page itself: it tells you who answered.

Who is returning the 404?

  • Laravel’s page (plain grey, 404 | Not Found): the request reached Laravel, which does not know the route. Go to causes 4 and 5.
  • The server’s page (white, text like 404 Not Found, sometimes mentioning LiteSpeed): the request never reached Laravel. Start with cause 1.

The ten-second test

Open https://example.com/index.php/login. If the login page appears, Laravel is fine and the missing piece is the rewrite rule that hides index.php from URLs.

Causes, most likely first

1. public/.htaccess is missing

Laravel ships an .htaccess inside public that sends every request that is not a real file to index.php. Because its name starts with a dot, it is the first file lost when zipping or uploading. Open File Manager, enable Show Hidden Files under Settings, and go into public (or public_html if you copied the contents of public there). If the file is missing, create it with this content, the essential part of Laravel’s own file:

<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_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

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

The Authorization lines pass API tokens through to PHP; keep them if you use Sanctum or JWT. The file is explained in what is .htaccess.

2. The document root points to the wrong place

The Document Root must point to the project’s public folder. Open Domains in cPanel and check the column. If the whole project sits in public_html with a root index.php that loads public/index.php, the home page works but every other route fails, because the rules in public/.htaccess do not apply to the root. The clean fix is to set the path to something like myapp/public. If you cannot change it, use the alternative in Laravel on cPanel without SSH.

3. Another .htaccess higher up overrides it

An old .htaccess in public_html from WordPress or a previous site can send requests to a different index.php or block them. Open it, remove any # BEGIN WordPress block or rules you do not recognise, and test again.

4. The route cache is stale

If php artisan route:cache ran on your computer or the server before the new routes existed, Laravel reads the saved list. Over SSH:

php artisan route:clear
php artisan route:list

The second command lists every route Laravel knows. Without SSH, delete bootstrap/cache/routes-v7.php in File Manager.

5. The route is not defined the way you think

  • Routes in routes/api.php always start with /api.
  • Linux is case-sensitive: a controller file userController.php does not match the class UserController, which usually gives a different error, covered in Target class does not exist.
  • /Products is not /products.

How to confirm it is fixed

Open two or three routes from route:list without index.php, and submit at least one form (POST). Then open a URL that does not exist: you should get Laravel’s own 404 page, not the server’s.

How to avoid it

  • Make sure your ZIP tool includes hidden files, and that public/.htaccess is committed when you deploy with Git.
  • Run php artisan route:cache on the server after deploying, not on your computer.
  • Follow the order in the Laravel deployment guide; if you get a 500 instead, see 500 error after uploading Laravel.

On ArabyHost

LiteSpeed reads Laravel’s .htaccess and its mod_rewrite rules as they are, so no server-side setup is needed. You change the Document Root under Domains in cPanel and show hidden files in File Manager. On AI/Developer plans you run artisan over SSH, and the Araby AI assistant reads the error log and explains the fix. More in Laravel hosting.

FAQ

Why was .htaccess not uploaded with the project?

Its name starts with a dot, so File Manager and some ZIP and FTP tools hide it by default. Enable Show Hidden Files in File Manager to check it is inside public.

Routes in routes/api.php return 404. Why?

Laravel prefixes every api.php route with /api, so the URL is example.com/api/users, not example.com/users. In Laravel 11, api.php must also be enabled with php artisan install:api.

I added a new route and it does not work on the server. Why?

Probably the route cache. If php artisan route:cache was run earlier, Laravel reads the saved list. Run php artisan route:clear or delete bootstrap/cache/routes-v7.php.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.