Laravel 4简单的路由无法使用mod_rewrite和.htaccess [英] Laravel 4 simple route not working using mod_rewrite, and .htaccess
问题描述
我不仅是Laravel 4的新手,还是使用框架的新手.我以为我会从Laravel开始,因为它获得了如此好的评价. 我已经很好地安装了Laravel.我转到/l4/public,然后看到欢迎页面.
I'm not only new to Laravel 4, but new to using frameworks. I thought I'd start with Laravel since it's gotten such good reviews. I've got a good install of Laravel. I go to /l4/public and see the welcome page.
我正在尝试向route.php添加一条路由,以便当我导航到/l4/public/articles时得到响应.
我收到在此服务器上找不到请求的URL/l4/public/articles".我需要运行工艺师命令来编译路线吗?这可能很容易.为什么显示此消息?
I'm trying to add a route to routes.php so that when I navigate to /l4/public/articles I get a response.
I get "The requested URL /l4/public/articles was not found on this server." Do I need to run an artisan command to compile the routes? It's probably something easy. Why this message?
routes.php
routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('articles', function ()
{
//return View::make('articles');
return "Articles hello there";
});
推荐答案
问题是通过对Apache的httpd.conf文件进行两次编辑更改来解决的.
Problem is solved by two editing changes in apache's httpd.conf file.
AllowOverride无为默认值. AllowOverride控制是否处理.htaccess文件.
AllowOverride None is default. AllowOverride controls whether .htaccess files are processed.
默认情况下,mod_rewrite被注释掉.
mod_rewrite is commented out by default.
要进行的更改:
更改1:通过取消注释来激活mod_rewrite.
Change 1: Activate mod_rewrite by uncommenting it.
更改2:
更改
AllowOverride None
到
AllowOverride All
现在重新启动Apache ...
Now restart Apache...
Laravel在公用文件夹中提供的默认.htaccess文件指定了一些mod_rewrite规则.由于AllowOverride设置为none,因此未应用这些规则.更改这些设置后,请确保并重新启动apache. 我的配置:Windows XP上的Apache 2.4.6.
The default .htaccess file that Laravel provides in the public folder specified some mod_rewrite rules. These rules were not getting applied because AllowOverride was set to none. Be sure and restart apache after changing these settings. My configuration: Apache 2.4.6 on Windows XP.
看来,AllowOverride更改可能会带来一些安全隐患.如果有人对此有其他信息,我想听听.
It appears that there may be some security implications to the AllowOverride change. If anyone has additional information on this, I would like to hear it.
这篇关于Laravel 4简单的路由无法使用mod_rewrite和.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!