I installed Laravel 4 using Composer and also set up a virtual host. Currently, only the root route is working:
<?php
Route::get('/', function()
{
return View::make('hello');
});
This is not:
Route::get('/hello', function()
{
return View::make('hello');
});
What I'm trying to hit is TasksController
at /tasks
:
Route::resource('tasks', 'TasksController');
This is giving me 404 error as well. What could I be doing wrong? I have a default .htaccess file at the root of my project:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I am using localhost on a Mac.
It's pretty clear that the problem appears because of the "mod_rewrite", in some cases just enabling this module in Apache is enough to get it fixed.
However, in my case, I had to extend the configuration for the VirtualHost in the following way:
It's like @GaryJ & @MartinGomez said. This is the content of the .htaccess that should be set on the public folder for all your laravel 4 projects running on Apache server:
For Nginx users, you probably copied the the
default
virtualhost - but Laravel requires some customization on thelocation
directive to allow the Laravel application to do the routing and not Nginx.In your
/etc/nginx/sites-available/your-site-name
replace the location directive with this:Then run
sudo service nginx reload
to make the changes come into effect.Had exactly the same problem.
Two things I needed to do to fix this:
Change the AllowOverride from None to All, example (Apache 2.4.9):
Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted
FYI: use Laravel Homestead together with VirtualBox and Vagrant instead of WAMP. It contains Nginx instead of Apache but everything works by default as it is configured for Laravel explicitly.
I had a similar problem on Ubuntu 14.04 with Lumen 5.4.
The solution was two parts for me. First in my vhost file
/etc/apache2/sites-enabled/my_vhost.conf
, I had to add the following<Directory>
entry to allow overrides, after declaring myDocumentRoot
:Next, I had to enable rewrites with:
FOR UBUNTU USERS - tested for Ubuntu 18.04
1- Enable mod rewrite
2- Change AllowOverride in apache conf file:
Change the AllowOverride from None to All in this block
3- Restart Apache