-1

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.

4
  • "DO NOT post images of code, data, error messages, etc.—copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text." - How to Ask a Good Question Commented Feb 26 at 17:17
  • Please also include your configuration file for Apache and copy and paste the actual 404 error responses. The configuration can affect how Apache routes your requests to your Laravel app. The type of 404 error may include information on where it is coming from (Apache vs Laravel). Commented Feb 26 at 17:20
  • Is the login URL giving the 404 exactly the same as the login URL that works? Commented Feb 26 at 18:50
  • Please provide enough code so others can better understand or reproduce the problem. Commented Feb 26 at 19:36

1 Answer 1

-1

What URL are you trying to access? In case of Xampp, it searches for index file in root directory. And laravel's index is present in public.

So either you need to configure apache to point public directory of your folder. Or simply try using public when accessing localhost. http://localhost/project-name/public/{route}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.