CodeIgniter Forums
problem with routes.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: problem with routes.php (/showthread.php?tid=43600)



problem with routes.php - El Forum - 07-17-2011

[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?


problem with routes.php - El Forum - 07-17-2011

[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;


problem with routes.php - El Forum - 07-17-2011

[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';



problem with routes.php - El Forum - 07-18-2011

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