Laravel 4 简单路线无法使用 mod_rewrite 和 .htaccess [英] Laravel 4 simple route not working using mod_rewrite, and .htaccess

查看:12
本文介绍了Laravel 4 简单路线无法使用 mod_rewrite 和 .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.

我正在尝试向 routes.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

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 None 是默认值.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屋!

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