Laravel 4 All Routes Except Home Result in 404 Error

65,533

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:

  1. Open apache httpd.conf and find this line :

    #LoadModule rewrite_module modules/mod_rewrite.so
    
  2. Uncomment this line (remove the #)
  3. Save httpd.conf
  4. 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:

  1. enable rewrite_module in Apache
  2. 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
Share:
65,533
Amit Erandole
Author by

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, 2022

Comments

  • Amit Erandole
    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
    Amit Erandole over 11 years
    crap! /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
    Amit Erandole over 11 years
    I don't get it: I have mod rewrite on and AllowOverride is set to All too
  • GaryJ
    GaryJ over 11 years
    Check if anything in .htaccess is working - if you're running Apache 2.4, note the changes since previous versions, regarding Require all granted and AllowOverride all within a <Directory />...</Directory> block on your virtual host. And reboot Apache for luck.
  • Amit Erandole
    Amit Erandole over 11 years
    rebooted and everything checks out fine but still no luck with the .htaccess file
  • GaryJ
    GaryJ over 11 years
    Try 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
    Amit Erandole over 11 years
    My 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
    GaryJ over 11 years
    Try: <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
    Amit Erandole over 11 years
    I 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
    GaryJ over 11 years
    You've definitely got the conf/extra/httpd-vhosts.conf file be included (uncommented) within the main httpd.conf?
  • Amit Erandole
    Amit Erandole over 11 years
    probably not. Where do I find this line?
  • Amit Erandole
    Amit Erandole over 11 years
    Here is my entire http.conf file for your perusal: d.pr/n/tKdp Do you see anything wrong here?
  • marienke
    marienke over 10 years
    I 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
    marienke over 10 years
    Please 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
    Jeff Lambert over 10 years
    On Ubuntu, this would be: sudo a2enmod rewrite followed by sudo service apache2 restart
  • Frendhi
    Frendhi over 9 years
    I 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
    Luca about 9 years
    this 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
    itsazzad about 9 years
    @AmitErandole Whoops. We seem to have missed the gist of that gist.github.com/4131966 you posted.
  • Abhishek Goel
    Abhishek Goel about 9 years
    perfect. Actually I forgot to copy .htaccess in my root directory
  • Can Tecim
    Can Tecim almost 9 years
    AllowOverride worked for me with fresh xampp install and vhost
  • Captain Hypertext
    Captain Hypertext over 8 years
    Perfect! This fixed my problem.
  • markov00
    markov00 over 8 years
    you and @GaryJ saved my day! Thanks
  • Richard Chassereau
    Richard Chassereau about 8 years
    I 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
    Mirko almost 8 years
    Thanks, this is it!
  • hanzo2001
    hanzo2001 over 7 years
    I 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
    Husam over 5 years
    Works, thaaanks
  • Janaka Dombawela
    Janaka Dombawela over 5 years
    Working on laravel 5.1 too. Nice!
  • Chandan Sharma
    Chandan Sharma over 4 years
    You first can check if mod_rewrite is enable or not.
  • Scott Yu - builds stuff
    Scott Yu - builds stuff about 4 years
    Good 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
    Fakher almost 3 years
    Works as charm on Ubuntu 20 with Laravel 8. Thanks !
  • Carlos Laspina
    Carlos Laspina over 2 years
    Works perfectly in Ubuntu 18 with Laravel 8. Does someone know the reason for this?