Laravel routes returning 404 after move from xampp to apache 2.4.7. mod_rewrite or htacess or missing apache setting?

StackOverflow https://stackoverflow.com/questions/21274344

Question

a simple 'test' route keeps returning a 404.

Route::get('test', function() {
    return View::make('test');
});

The route doesn't work whether it's localhost/test, or vhost.dev/test or even when using our sub.domain.com/test with the DNS pointing to that particular laptop.

We were using XAMPP but switched to apache after learning that xampp was not suitable for a production environment. So I installed apache 2.4.7, php and the various sqlsrv mods on one of our win7 laptops. After moving to Apache, all routes have stopped working even with the same directory structure.

I've also tried moving all files in /public into /htdocs and the rest of the app into a laravel folder in the root apache2.4 folder.

I'm tested if mod_rewrite is enabled using this code on SO. This is the response so I suppose it is working?

Apache/2.4.7 (Win32) PHP/5.4.24

mod_rewrite available

htaccess

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Was it helpful?

Solution

This was answered on the Laravel forums.

The problem was because AllowOverride was set to None in Apache. Changing that to All solved all the routing problems.

Here is the example virtual host configuration from the post:

<VirtualHost *:80>
    ServerAdmin youremail@yahoo.com
    ServerName yoursite.com
    ServerAlias www.yoursite.com
    DocumentRoot "/var/www/yoursite.com/public"
    <Directory /var/www/yoursite.com/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

OTHER TIPS

Is mod_rewrite enabled on the new server?

a2enmod rewrite

You should try http://localhost/laravel/public/index.php/test and that should work. Also you should consider using nginx as server, that's more flexible than apache.

In above http link, laravel is your laravel directory

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top