Home » Php » Laravel 4 .htaccess Not Rewriting URLs

Laravel 4 .htaccess Not Rewriting URLs

Posted by: admin October 29, 2017 Leave a comment

Questions:

So I’ve just upgraded to Laravel 4, and I’m setting things up on a new server. The default / route works fine, but every other route returns a 404 error. When trying index.php/route, I get the requested data, so that means that .htaccess isn’t working.

Yes, AllowOverride is set to ALL.
Yes, I enabled the mod_rewrite module.

I have tried the following 3 .htaccess combinations:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

and:

<IfModule mod_rewrite.c>
   RewriteEngine on

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d

   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

and:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

And, after a server restart, and so on, none of them are working, and I’m still returning a 404 error.

Note: I am using several domains with the same laravel install, so my public folders are public/site1, public/site2, public/site3. However, I am routing the public paths to these folders, so I’m not sure that would be the problem.

Any thoughts?

Answers:

I forgot to edit the vhosts in httpd.conf. Derp, derp.
Added:

<Directory "/var/www/public/site1">
    AllowOverride All
</Directory>

to each of the site’s vhost files, and it worked beautifully. Derp derp.