PHP Laravel Routing Issue
Asked Answered
K

4

7

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.

Keirakeiser answered 20/8, 2012 at 22:4 Comment(7)
The last route? What is it for other than to tread on the controllers toes... that coincidentally needs to be capitalised from my understanding of Laravel, Register_Controller. I can't see why it's not throwing a laravel 404 mind you.Coetaneous
I've already tried capitalizing, tried it without that last Route. I added it because nothing else works, and since routes are evaluated in the order presented it can't possibly tread on the controllers, right? My feeling right now is that something's wrong with the PHP settings.Keirakeiser
Capitalised is correct, at least in terms of all the Laravel docs I've read. I can tell you that the last route is totally unecessary. If the controller isn't being auto detected declare it: Route::Controller(array('register'));Coetaneous
Also is register.php in the controllers directory and not in a sub directory of it?Coetaneous
register.php is not in a subdirectory. I've tried both the array and the single routing method, both to no avail.Keirakeiser
Laravel is supposed to catch all 404s right? /index gets caught but anything else does not. I still feel like there's some PHP/Apache configuration issues.Keirakeiser
let us continue this discussion in chatCoetaneous
K
10

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

Keirakeiser answered 22/8, 2012 at 17:59 Comment(0)
T
5

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.

Tahsildar answered 22/8, 2012 at 14:34 Comment(3)
phpinfo() confirms that mod_rewrite is loaded, but it still does not work. Would having it on Ubuntu as a virtualhost be a cause?Keirakeiser
It works on my Mint Linux (which is an Ubuntu derivative). I cannot imagine why being on a virtual host could be the cause.Tahsildar
I got it! AllowOverride All fixed itKeirakeiser
T
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

Transformer answered 21/8, 2012 at 12:36 Comment(0)
R
2

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());
Rumelia answered 12/9, 2012 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.