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>
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.
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>
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With