Laravel除"/"外的所有路线均返回404 [英] Laravel all routes except '/' return 404

查看:97
本文介绍了Laravel除"/"外的所有路线均返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我的laravel应用程序中除home('/')路由以外的所有路由都会导致404错误.

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

我已将公共文件夹与laravel应用程序的其余部分分开,如下面的文件夹结构所示. 我已经确认这不是引起问题的原因.

I have separated the public folder from the rest of the laravel app as represented in the folder structure below. 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).

我忘了提及:如果我转到localhost/index.php/route_name

文件夹结构:(为了方便起见,文件夹名称更改为public/和laravel/)

.
+-- 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 :(未修改)

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

在stackoverflow上存在几乎相同的问题,但没有提供答案.

我该如何解决?

推荐答案

在apache2.conf中将AllowOverride设置为全部并使用命令a2enmod rewrite启用mod_rewrite后,所有方法都可以正常工作.

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

这篇关于Laravel除"/"外的所有路线均返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆