Laravel 4 All Routes Except Home Result in 404 Error
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.
Solution 1:
Just for a laugh, see if /index.php/hello
works.
If so, then most likely it's a .htaccess
problem.
Solution 2:
Had the same problem running Laravel 4 on WAMP (Windows 8).
The solution that worked for me was:
-
Open apache httpd.conf and find this line :
#LoadModule rewrite_module modules/mod_rewrite.so
- Uncomment this line (remove the
#
) - Save
httpd.conf
- Restart WAMP
It should be working!
Solution 3:
I had the same problem and the solution was enable the rewrite mod on Apache2
In a terminal use the following commands:
$ sudo a2enmod rewrite
$ sudo service apache2 restart
And magic!
Solution 4:
Had exactly the same problem.
Two things I needed to do to fix this:
- enable rewrite_module in Apache
-
Change the AllowOverride from None to All, example (Apache 2.4.9):
<Directory "c:/www"> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory>
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.
Solution 5:
FOR UBUNTU USERS - tested for Ubuntu 18.04
1- Enable mod rewrite
sudo a2enmod rewrite
2- Change AllowOverride in apache conf file:
sudo nano /etc/apache2/apache2.conf
Change the AllowOverride from None to All in this block
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
3- Restart Apache
sudo service apache2 restart