简体   繁体   中英

Error with routes in Laravel 5.0

I have a problem when I use routes in Laravel 5.0, I only need to call this route:

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

But the browser shows me this, when I write http://localhost/course/public/home :

Not Found
The requested URL /course/public/home was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80

If I write http://localhost/course/public/ the index works but the other routes doesn't work, I don't know why.

In my Routes.php I have this:

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

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

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

I only downloaded laravel 5.0 with composer, I did not change nothing in the code after the download, I only want to test the routes and these don't work.

Thaks for your help.

in conclusion (the comments solved the problem, so thank you guys for this!!) you probably run Laravel on Apache and you don't have mod_rewrite enabled... or not configured correctly.

Laravel works with so called pretty urls. In order to achieve this, every request is rewritten and the config you can find in the .htaccess file in the public folder. This to give a quick and dirty explanation will let you write URLs without the index.php .

Additionally your server should serve the public folder and not the main folder. That's a security thing if you want to use your site in production.

Alternatively you can use nginx which in my opinion is a lot easier to configure and if you run laravel homestead everything comes straight out of the box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM