Laravel 4 简单路由无法使用 mod_rewrite 和 .htaccess

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17772962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:33:41  来源:igfitidea点击:

Laravel 4 simple route not working using mod_rewrite, and .htaccess

laravellaravel-4

提问by Alex_B

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.

我不仅是 Laravel 4 的新手,也是使用框架的新手。我想我会从 Laravel 开始,因为它得到了如此好的评价。我已经很好地安装了 Laravel。我转到 /l4/public 并查看欢迎页面。

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 添加路由,以便在导航到 /l4/public/articles 时得到响应。
我收到“在此服务器上找不到请求的 URL /l4/public/articles”。我是否需要运行工匠命令来编译路由?这可能是很容易的事情。为什么是这个消息?

routes.php

路由文件

Route::get('/', function()
{
    return View::make('hello');
});

Route::get('articles', function ()
{
    //return View::make('articles');
    return "Articles hello there";
});

回答by Alex_B

Problem is solved by two editing changes in apache's httpd.conf file.

问题通过 apache 的 httpd.conf 文件中的两个编辑更改解决。

AllowOverride None is default. AllowOverride controls whether .htaccess files are processed.

AllowOverride None 是默认值。AllowOverride 控制是否处理 .htaccess 文件。

mod_rewrite is commented out by default.

mod_rewrite 默认被注释掉。

Changes to make:

要进行的更改:

Change 1: Activate mod_rewrite by uncommenting it.

更改 1:通过取消注释来激活 mod_rewrite。

Change 2:

变化2:

Change

改变

AllowOverride None

to

AllowOverride All

Now restart Apache...

现在重新启动Apache...

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.

Laravel 在 public 文件夹中提供的默认 .htaccess 文件指定了一些 mod_rewrite 规则。这些规则没有得到应用,因​​为 AllowOverride 设置为 none。请务必在更改这些设置后重新启动 apache。我的配置:Windows XP 上的 Apache 2.4.6。

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.

看来 AllowOverride 更改可能存在一些安全隐患。如果有人对此有更多信息,我想听听。

回答by reptildarat

That Error basically say that the router cannot found your request. Make sure you already save your changes. if you using the artisan command to running the page,just re-run again command "artisan Serve".

该错误基本上是说路由器找不到您的请求。确保您已经保存了您的更改。如果您使用 artisan 命令来运行页面,只需重新运行命令“artisan Serve”。

回答by Blue Genie

You need mod_rewrite on. Try: l4/public/index.php/articles

您需要打开 mod_rewrite。试试:l4/public/index.php/articles

回答by Oday M. Saed

in httpd.conf change

在 httpd.conf 更改

<Directory />
    AllowOverride none
    Require all granted
</Directory>

to

<Directory />
    AllowOverride all
    Require all granted
</Directory>

then uncomment

然后取消注释

#LoadModule rewrite_module modules/mod_rewrite.so

to

LoadModule rewrite_module modules/mod_rewrite.so