PHP Laravel路由问题


PHP Laravel Routing Issue

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

application/controllers/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有效。

mydomain.com/index提供laravel 404

mydomain.com/register提供标准的404

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

打开mod_rewrite后,尝试在apache配置中设置"AllowOverride All",它为我修复了它。

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

sudo a2enmod rewrite

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

您可以使用PHP命令

phpinfo();

以检查mod_rewrite是否工作。

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

取消注释以下行

LoadModule rewrite_module modules/mod_rewrite.so

并重新启动httpd

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

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