Laravel route returns 404 when accessing via localhost, but works with php artisan serve I downloaded Laravel and wrote some routes and views. Then, I used XAMPP to start Apache and MySQL. After that, I tried accessing the website via localhost, but some routes didn't work and returned a 404 error.
However, when I ran php artisan serve, everything worked correctly.
MY laravel version : php artisan --version Laravel Framework 11.42.1
This is my route : enter image description here
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return
"<a href='".route('custom_admin_role')."'>Login</a>";//404 error
//on page /login when click link
});
Route::get('home', function () {//404 error
return view('home');
});
Route::get('/welcome', function () {//work
return " welcome you all ";
});
Route::get('/welcome/{name}', function ($name) {//work
return " welcome ${name} ";
});
Route::get('/login', function () { //work if enter without link
Login
return "<h1>Login success</h1>";//404 error
})->name('custom_admin_role');
Issue: When clicking the "Login" link on the homepage (/), it returns a 404 error on /login. Entering /login manually in the browser works fine. The home route (/home) also returns 404 when accessed.