Laravel 4 All Routes Except Home Result in 404 Error
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
Amit Erandole
I am the content head of my very own web marketing agency, based out of Mumbai. I am a writer by profession but the dark side of my nature seems to have turned towards programming. I will have my vengeance!! I love learning javascript and ruby and amazed by the power of meta programming and shit I don't know but am very curious about.
Updated on July 05, 2022Comments
-
Amit Erandole almost 2 years
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.
-
Amit Erandole over 11 yearscrap! /index.php/hello works but /index.php/tasks gives me a 500 error now. WTF? I'll update my question with the htaccess contents
-
Amit Erandole over 11 yearsI don't get it: I have mod rewrite on and AllowOverride is set to All too
-
GaryJ over 11 yearsCheck if anything in .htaccess is working - if you're running Apache 2.4, note the changes since previous versions, regarding
Require all granted
andAllowOverride all
within a<Directory />...</Directory>
block on your virtual host. And reboot Apache for luck. -
Amit Erandole over 11 yearsrebooted and everything checks out fine but still no luck with the .htaccess file
-
GaryJ over 11 yearsTry removing the IfModule conditional. As you've got access to the host / vhost, you can soon enable that module if it's not - so it doesn't need be checked on every request. Equally, try moving it out of .htaccess, and into a
<Directory />...</Directory>
block in your vhost - if you've got nothing else in your .htaccess it can then be deleted as well. -
Amit Erandole over 11 yearsMy http-vhosts block looks like this: <VirtualHost *:80> DocumentRoot "/Users/amiterandole/Sites/laravelbackbone/public" ServerName laravelbackbone.dev </VirtualHost> What exactly should I move into this?
-
GaryJ over 11 yearsTry: <VirtualHost *:80> DocumentRoot "/Users/amiterandole/Sites/laravelbackbone/public" ServerName laravelbackbone.dev <Directory /> AllowOverride all Require all granted </Directory> <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> </VirtualHost>
-
Amit Erandole over 11 yearsI emptied out my htaccess file and tried the above and now nothing seems to work. Now laravelbackbone.dev points to my Sites folder root for some reason (?!)
-
GaryJ over 11 yearsYou've definitely got the
conf/extra/httpd-vhosts.conf
file be included (uncommented) within the mainhttpd.conf
? -
Amit Erandole over 11 yearsprobably not. Where do I find this line?
-
Amit Erandole over 11 yearsHere is my entire http.conf file for your perusal: d.pr/n/tKdp Do you see anything wrong here?
-
marienke over 10 yearsI don't have #LoadModule rewrite_module modules/mod_rewrite.so in my httpd.conf :( is that a Windows8 thing? I'm using XAMPP on Windows7
-
marienke over 10 yearsPlease help? I've got the same vhost set up (obviously different DocumentRoot), I've also emptied (and tried deletion of) the .htaccess file, I'm including conf/extra/httpd-vhots.conf in my main httpd.conf file. I'm up to the point where Amit said laravelbackbone.dev points to his Sites folder root, except, I get a Bad Request. Please see my question here: stackoverflow.com/questions/18859352/…
-
Jeff Lambert over 10 yearsOn Ubuntu, this would be:
sudo a2enmod rewrite
followed bysudo service apache2 restart
-
Frendhi over 9 yearsI had the same problem, using Ubuntu server 14.04. Was using alias in apache2.conf, the mod_alias already enabled. Adding rewritebase to file .htaccess on public folder did solve the problem. Thanks!
-
Luca about 9 yearsthis worked for me when deploying on my server. Vagrant is a good suggestion, more explicitly I'd suggest either laravel.com/docs/4.2/homestead or box.scotch.io if you want to stick to Apache
-
itsazzad about 9 years@AmitErandole Whoops. We seem to have missed the gist of that gist.github.com/4131966 you posted.
-
Abhishek Goel about 9 yearsperfect. Actually I forgot to copy .htaccess in my root directory
-
Can Tecim almost 9 yearsAllowOverride worked for me with fresh xampp install and vhost
-
Captain Hypertext over 8 yearsPerfect! This fixed my problem.
-
markov00 over 8 yearsyou and @GaryJ saved my day! Thanks
-
Richard Chassereau about 8 yearsI had the exact same issue. I also performed the "sudo a2enmod rewrite" command for apache, and then changed AllOverride from None to All in the apache2.conf file.
-
Mirko almost 8 yearsThanks, this is it!
-
hanzo2001 over 7 yearsI just want to add that you might need to set
AllowOverride FileInfo
to the directory in httpd.conf or just move the rewrite directives to that directory segment and forego the.htaccess
file -
Husam over 5 yearsWorks, thaaanks
-
Janaka Dombawela over 5 yearsWorking on laravel 5.1 too. Nice!
-
Chandan Sharma over 4 yearsYou first can check if mod_rewrite is enable or not.
-
Scott Yu - builds stuff about 4 yearsGood lord.. this is the ONLY thing that worked after hours of doing everything else imaginable. I am using Laravel 7... it's been nightmare trying to run some Laravel apps and installing. I wish they would have better error handling to let people know what's wrong on the page if debug is turned on. Maybe it's because I am installing an older Laravel app. Seems really difficult process.
-
Fakher almost 3 yearsWorks as charm on Ubuntu 20 with Laravel 8. Thanks !
-
Carlos Laspina over 2 yearsWorks perfectly in Ubuntu 18 with Laravel 8. Does someone know the reason for this?