Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RuzHan's avatar

All routes except '\' return 404 on a fresh Laravel project

Every route except for the default one i.e '\' returns a 404 page.

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('/test', function(){
    echo 'test';
});

.htaccess

<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 Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Note:

  1. The '/test' route works when using php artisan serve instead of "localhost\project\public"
  2. The '/test' route also works when using "localhost\project\public\index.php\test" after moving .htaccess from public/ to root of project
  3. This has only been happening with new laravel projects, older projects are working fine.

Steps I have taken already:

  1. Reinstalled xampp
  2. Made sure the line LoadModule rewrite_module modules/mod_rewrite.so is not-commented in httpd.conf
  3. Made sure all AllowOverride are set to All in httpd.conf
  4. Tested on multiple clean new laravel installations
  5. Tried php aritsan route:clear, config:clear, composer dump autoload, php artisan optimize

Apache version 2.4.58 xampp version 8.2.12 PHP version 8.2.12 Laravel Framework 10.38.2

0 likes
3 replies
RuzHan's avatar

Right, didn't solve the problem. Thank youuuuuuuu tho :)

jlrdw's avatar

@RoshanJafri After you correctly point to public as your document root. Of course you have to restart the server.

And setting up laravel correctly does work.

Edit:

A fresh laravel Install is not ready for use, Taylor has no idea if you are going to use nginx or apache, It's up to the developer to learn how to correctly set up the server.

A correct setup is usually a three or four minutes.

1 like

Please or to participate in this conversation.