问题
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?
回答1:
After setting AllowOverride to all in apache2.conf and enabling mod_rewrite with the command a2enmod rewrite
it all works.
回答2:
I understand this is an old question but want to post my solution here. It might help others.
It is mainly the issue with apache virtual host. After the DocumentRoot, make sure you have the following script available in the vhost config file.
<Directory "/var/www/path/to/my/app/public">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Another reason could be to enable apache rewrite mod. You can do it by using the following commands.
sudo a2enmod rewrite
sudo service apache2 restart
回答3:
put
index.php
and
.httaccess
in same directory.
it's work for me
来源:https://stackoverflow.com/questions/24147460/laravel-all-routes-except-return-404