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

ocupado's avatar

Laravel 5: The requested URL was not found on this server.

I 'm beginning to test Laravel and I 'm doing with version 5 but I am having problems with controllers. It happens that in a very simple example where I want test a route, Laravel 5 tells me not to get that URL.

The controller is this :

use App\Http\Requests;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class AboutController extends Controller {

function index()

{
    return "some message";

}

}

The routes are:

Route::get('about', 'AboutController@index');

Route::get('/', 'WelcomeController@index');

Route::get('home', 'HomeController@index');

Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ]);

When i try http://localhost/laravel/public/about/ appears the message: The requested URL /laravel/public/about/ was not found on this server.

The routes via php artisan:list are:

+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+

| | GET|HEAD | about | | App\Http\Controllers\AboutController@index | |

| | GET|HEAD | / | | App\Http\Controllers\WelcomeController@index | guest |

| | GET|HEAD | home | | App\Http\Controllers\HomeController@index | auth |

| | GET|HEAD | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getRegister | guest |

| | POST | auth/register/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postRegister | guest |

| | GET|HEAD | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogin | guest |

| | POST | auth/login/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@postLogin | guest |

| | GET|HEAD | auth/logout/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\AuthController@getLogout | |

| | GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | | App\Http\Controllers\Auth\AuthController@missingMethod | guest |

| | GET|HEAD | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getEmail | guest |

| | POST | password/email/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postEmail | guest |

| | GET|HEAD | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@getReset | guest |

| | POST | password/reset/{one?}/{two?}/{three?}/{four?}/{five?} | | App\Http\Controllers\Auth\PasswordController@postReset | guest |

| | GET|HEAD|POST|PUT|PATCH|DELETE | password/{_missing} | | App\Http\Controllers\Auth\PasswordController@missingMethod | guest |

+--------+--------------------------------+-------------------------------------------------------+------+------------------------------------------------------------+------------+

0 likes
15 replies
bestmomo's avatar

Could you format your code with with 3 "`" before and after ?

I think you miss the namespace in your controller.

<?php namespace App\Http\Controllers;
ocupado's avatar

It has. In previous post this line was deleted.

`<?php namespace App\Http\Controllers;

use App\Http\Requests;use App\Http\Controllers\Controller;

`use Illuminate\Http\Request;

`class AboutController extends Controller {

function index() { return "some message"; } }

ocupado's avatar

Yes. I've installed wamp and all the laravel site is under localhost (wamp/www/laravel)

michaeldyrynda's avatar

Best option is to set /laravel/public as your document root.

If you can't do that for whatever reason, you'll need to add a .htaccess file in the laravel directory to rewrite all your requests to the public folder - see here for more info.

ocupado's avatar

hello deringer,

In fact, the root is /laravel/public.

usman's avatar

@ocupado enable the mode_rewrite . You can do this by uncomment the following line in httpd.conf:

#LoadModule rewrite_module modules/mod_rewrite.so
4 likes
Snapey's avatar

no, the root is localhost/

so your about page will be at localhost/about

ocupado's avatar

usman,

After enable mode_rewrite, everything is runing Ok. Thanks. This is the solution to this issue.

Snapey,

The root directory in Laravel 5 is (nameofyourproject)/public. --> http://laravel.com/docs/5.0/structure I thing is possible to change that but i'm just startting with L5.

mehrancodes's avatar

It's too late for answering, but it still can help other devs.

So It may that under public you have a folder name as "about". That can be source of your problems.

6 likes
Martijn_van_der_Bruggen's avatar

In reply to Usman's answer, a little shortcut:

a2enmod rewrite  

(from the console, if your get an error you need to sudo.)

basically your saying: take this available apache2 module and make it active.

Restart apache2 after this.

Talky's avatar

Well the solution mehran sent is my kind of problem. So if you are struggling at "The requested URL was not found on this server." error even though you are sure your routes are there and should work, here's the thing-

YOU CANNOT HAVE THE SAME NAMED FOLDERS IN VIEWS and PUBLIC FOLDERS.

So if you have user/create route set up, but you also create folder 'user' in your public directory, Laravel will look for the route in public/user instead of resources/views/user. Don't know why this happens though.

3 likes
Snapey's avatar

@Talky the issue you describe is nothing to do with Laravel. the .htaccess file will use a folder or file that exists on the server in preference to redirecting to index.php. This is so that things like static css and image files can be sent without having to fire up php for each request.

1 like

Please or to participate in this conversation.