Mohamed Bouallegue
Mohamed Bouallegue

Reputation: 1362

Laravel route NotFoundHttpException

I'm starting a new Laravel project, I defined one route and this is my routes.php file

 <?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('signup', function()
{
    return View::make('signup');
});

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

when I try to load the page http://localhost/laravel-project/public/signup I get a HttpNotFoundException I run artisan routes and the route signup exist. how can I solve this problem?

Upvotes: 2

Views: 4403

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

The NotFoundHttpException exception is, 100% of the time, Laravel not being able to, somehow, find your route. So, there are some thing you need to be sure are working fine:

1) Check if your VirtualHosts are well configured. By trying to access with public in your URL:

http://localhost/laravel-project/public/signup

I can tell that something is wrong in there, because if you really had your virtualhost well configured, you should not be able to have access to your app folder and this should be your home:

http://localhost/laravel-project/

And then your signup route would have to be in:

http://localhost/laravel-project/signup

So, basically your virtualhost should point your root to the public folder, removing the need of it in your urls.

2) Check your .htaccess rewriting rules. Can you access your route by using one of those?:

http://localhost/laravel-project/public/index.php/signup

or

http://localhost/laravel-project/index.php/signup

If your .htaccess file is not in place or if you don't have the rewrite module installed or enabled, it will work, but they shouldn't, unless you want them to work this way. But this is also something that my give you a NotFoundHttpException, because you are not querying your public/index.php file, which is, basically, your application boostrapper.

Upvotes: 2

Related Questions