【发布时间】:2014-07-31 14:20:54
【问题描述】:
正如标题所说,我的 laravel 应用中除了 home('/') 路由之外的所有路由都会导致 404 错误。
我已将公用文件夹与 laravel 应用程序的其余部分分开,如下面的文件夹结构所示。 编辑:我已经确认这不是导致问题的原因。
开发系统(本地)和生产系统(共享主机)都会出现此错误。
编辑:我忘了说:如果我去 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>
There exists an almost identical question here on stackoverflow,但它没有提供答案。
我该如何解决这个问题?
【问题讨论】:
-
您的 Apache 配置是否允许
.htaccess覆盖,就像我上一个回答中一样:index.php still needed, even after .htaccess -
是的。我之前也在我的共享主机上托管了一个 Laravel 应用程序,没有类似的问题。
-
在您的 bootstrap/paths.php 中尝试将 public 更改为
'public' => __DIR__.'/../public' -
那行不通,米奇。
-
你确定在服务器上启用了 mod_rewrite 吗?只是试图排除明显的......
标签: php .htaccess laravel laravel-4