Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel all routes except '/' return 404

As the title says, all the routes in my laravel app except the home('/') route result in a 404 error.

I have separated the public folder from the rest of the laravel app as represented in the folder structure below. EDIT: I have confirmed that this is not what's causing the problem.

This error occurs on both the development system (local) and the production system (shared hosting).

EDIT: I forgot to mention: routes work if I go to localhost/index.php/route_name

Folder structure: (folder names changed to public/ and laravel/ for convenience)

.
+-- public/
|    +-- index.php
|    +-- packages/
|    +-- etc...
+-- laravel/
|    +-- app/
|    +-- artisan
|    +-- etc...

routes.php:

<?php
Route::get('/', function() // Only this route works
{
    return 'hello world';
});

Route::get('oversikt', function() // This route does not work
{
    return 'goodbye world';
});

bootstrap/paths.php:

<?php
return array(
    'app' => __DIR__.'/../app',
    'public' => __DIR__.'/../../pc',
    'base' => __DIR__.'/..',
    'storage' => __DIR__.'/../app/storage',
);

index.php:

<?php
require __DIR__.'/../pc_backend/bootstrap/autoload.php';
$app = require_once __DIR__.'/../pc_backend/bootstrap/start.php';
$app->run();

.htaccess: (unmodified)

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

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

There exists an almost identical question here on stackoverflow, but it does not provide an answer.

How can I resolve this?

like image 250
hansn Avatar asked Jun 10 '14 17:06

hansn


1 Answers

After setting AllowOverride to all in apache2.conf and enabling mod_rewrite with the command a2enmod rewrite it all works.

like image 150
hansn Avatar answered Oct 21 '22 15:10

hansn