PHP Laravel 路由问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12045881/
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-14 07:23:13  来源:igfitidea点击:

PHP Laravel Routing Issue

phpurl-routinglaravellaravel-3

提问by wonton

My setup currently looks like this

我的设置目前看起来像这样

application/controllers/register.php

应用程序/控制器/register.php

class register_Controller extends Base_Controller
{
    public $restful = true;
    public function get_index()
    {
        return View::make('main.register');;
    }
}

routes.php

路由文件

Route::controller(Controller::detect());
Route::any('/', function()
{
    return View::make('main.index');
});
Route::any('register',function()
{
    return View::make('register.index');
});

mydomain.com works.

mydomain.com 有效。

mydomain.com/index gives a laravel 404

mydomain.com/index 给出了一个 Laravel 404

mydomain.com/register gives a standard 404

mydomain.com/register 给出了一个标准的 404

What's strange is that shouldn't mydomain.com/register give me a laravel 404 error? Thispage indicates that WAMP was the cause, but my setup is on a Ubuntu VM running PHP5, Apache2, and mySQL.

奇怪的是 mydomain.com/register 不应该给我一个 Laravel 404 错误吗? 页面表明 WAMP 是原因,但我的设置是在运行 PHP5、Apache2 和 mySQL 的 Ubuntu VM 上。

回答by wonton

With mod_rewrite on, try setting in apache configurations "AllowOverride All", it fixed it for me.

启用 mod_rewrite,尝试在 apache 配置中设置“AllowOverride All”,它为我修复了它。

回答by Hendrik Jan

As Akash suggests, make sure your mod_rewrite is enabled. On Ubuntu use the following command to enable mod_rewrite on Apache:

正如 Akash 建议的那样,确保您的 mod_rewrite 已启用。在 Ubuntu 上,使用以下命令在 Apache 上启用 mod_rewrite:

sudo a2enmod rewrite

(You don't have to edit httpd.conf)
Do not forget to restart apache.

(您不必编辑 httpd.conf)
不要忘记重新启动 apache。

You can use the PHP command

您可以使用 PHP 命令

phpinfo();

to check if mod_rewrite is working.

检查 mod_rewrite 是否正常工作。

回答by Akash

make sure mod_rewrite is turned on in Apache (httpd.conf)

确保在 Apache (httpd.conf) 中打开了 mod_rewrite

Un-comment the following line

取消注释以下行

LoadModule rewrite_module modules/mod_rewrite.so

and restart httpd

并重启httpd

回答by Akash

In addition, you should set your routes before you detect your controllers.

此外,您应该在检测控制器之前设置路由。

Route::any('/', function()
{
    return View::make('main.index');
});

Route::any('register',function()
{
    return View::make('register.index');
});

Route::controller(Controller::detect());