Routes not working without index.php

RSM picture RSM · Feb 9, 2014 · Viewed 18.4k times · Source

Im using laravel 4.

I have a view nest.blade.php and the corresponding controller NestController.php:

Controller content:

class NestController extends BaseController {

    public function showView()
    {
        return View::make('nest');
    }

}

Route:

Route::get('/nest', 'NestController@showView');

When I go to url/nest it doesnt work. When I go to url/index.php/nest it does work.

Obviously I just want it to be /nest without the index.php.

How can i resolve this?

My htaccess:

IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Answer

The Alpha picture The Alpha · Feb 9, 2014

Pretty URLs

The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

For more related help, check this answer.