【发布时间】:2014-06-29 00:31:21
【问题描述】:
我刚开始学习 laravel 4,但我遇到了路线问题。当我转到我的根 url 时,路由似乎工作正常,但是当我尝试访问我的第二条路由时,我收到 404 错误,并且服务器日志显示“找不到文件”错误。
我设置了 AllowOverride ALL 并将原来的 .htaccess 代码更改为我在下面发布的代码。
注意: example.com 正在运行,它会按预期返回 All cats。
这是代码:
路线
Route::get('/', function(){
return "All cats";
});
Route::get('cats/{id}',function($id){
return "Cat #$id";
})->where('id','[0-9]+');
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
httpd.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/cats/public
ServerName example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
</VirtualHost>
尝试访问 example.com/cats/123 时出现 HTML 错误
The requested URL /cats/123 was not found on this server.
错误日志
File does not exist: /var/www/html/cats/public/cats
【问题讨论】:
-
为什么不能使用 Laravel 提供的原始 .htaccess 呢?
-
我正在使用它,但它不起作用,我看到很多人都在改用我上面发布的那个。
-
改回原来的 htaccess 并在你的虚拟主机配置中添加 AllowOverride All。
-
我尝试在 VH 中添加 AllowOverride ALL,但出现错误,所以我将其留在原处。
-
在 VH 配置中添加 Allowoverride 时遇到什么错误?