Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routes not working without index.php

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>
like image 708
RSM Avatar asked Feb 09 '14 17:02

RSM


4 Answers

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.

like image 160
The Alpha Avatar answered Oct 19 '22 22:10

The Alpha


I enabled the mod_rewrite module in the Apache HTTP server, restarted Apache service and tested again and it WORKED!!!

Below is the code i used to enable mode_rewrite;

1) Un-Hash this line in Apache/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

2) Create a new configuration for "sample-project" without modifying the default configuration in the httpd.conf file

Directory "C:/Apache24/htdocs/sample-project">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  Allow from all
Directory>
like image 32
developer86 Avatar answered Oct 19 '22 23:10

developer86


Be Alert! If it is not working even after enabling rewrite module. You need to change the line "AllowOverride None" to "AllowOverride All" in httpd.conf.

As @The Alpha alerted, Laravel don't need to be configured for this purpose.

like image 4
Wanderson Xesquevixos de Sique Avatar answered Oct 19 '22 23:10

Wanderson Xesquevixos de Sique


When you change the line AllowOverride None to AllowOverride All in httpd.conf be sure that you do it inside <directory ...> that contains valid path.

Example

<Directory "/var/www/html"> #check path
   Options Indexes FollowSymLinks
   AllowOverride All
</Directory>
like image 2
Max Desmos Avatar answered Oct 19 '22 22:10

Max Desmos