PHP Laravel Routing Issue

有些话、适合烂在心里 提交于 2019-12-09 11:29:31

问题


My setup currently looks like this

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 works.

mydomain.com/index gives a laravel 404

mydomain.com/register gives a standard 404

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


回答1:


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




回答2:


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

sudo a2enmod rewrite

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

You can use the PHP command

phpinfo();

to check if mod_rewrite is working.




回答3:


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

Un-comment the following line

LoadModule rewrite_module modules/mod_rewrite.so

and restart httpd




回答4:


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());


来源:https://stackoverflow.com/questions/12045881/php-laravel-routing-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!