CodeIgniter Forums

Full Version: problem with routes.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]rufisgumbo[/eluser]
I have a controller named <b>controllers/contact.php</b>

I want to load this controller using either of these URLS:

website.com/contact
website.com/members/contact

So I put this in routes.php:

Code:
$route['members/contact/(:any)'] = 'contact/$1';

Yet if I load /members/contact now, it just returns a 404. What am I missing?

El Forum

[eluser]John_Betong_002[/eluser]
Try this:

Code:
$route["members/contact"]        = "contact";      // defaults to index()
$route["members/contact/(:any)"] = "contact/$1";   // looks for a $1 method
&nbsp;

El Forum

[eluser]Aken[/eluser]
John's code might work, but you should always define the most specific routes first, so they are picked up in the proper order.
Code:
$route['members/contact/(:any)'] = 'contact/$1';
$route['members/contact'] = 'contact';

If you don't have any other functions in your contact controller, and will only need to use that controller from one of the two URLs mentioned, you can avoid the :any part.
Code:
$route['members/contact'] = 'contact';

El Forum

[eluser]rufisgumbo[/eluser]
Thanks guys, working.