CodeIgniter Forums
regular expression trouble... - 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: regular expression trouble... (/showthread.php?tid=2147)



regular expression trouble... - El Forum - 07-18-2007

[eluser]danoph[/eluser]
i am trying to route URLS such as http://localhost/contact to http://localhost/home/contact UNLESS $1 is sell or store using the following route. http://localhost/sell and http://localhost/store link to the right controllers, but if the method isn't one of those two, I get a 404 error. I am obviously doing this wrong. Can anyone help me out?

$route['!^(sell|store)'] = "home/$1";


regular expression trouble... - El Forum - 07-18-2007

[eluser]sophistry[/eluser]
why don't you use multiple routes one for sell and one for store and then use the handy :any shortcut to route everything else. so 3 routing rules in all.

does that work?


regular expression trouble... - El Forum - 07-18-2007

[eluser]danoph[/eluser]
i found a solution.

$route['^(?!store|sell).*'] = "home/$0";

this allows for multiple controllers (store and sell) as well as functions within a certain controller (home) to use simple urls:

http://localhost/contact (uses home controller, function contact)
http://localhost/sell (uses sell controller)
http://localhost/store (uses store controller)


regular expression trouble... - El Forum - 07-18-2007

[eluser]danoph[/eluser]
heh, i guess that would have worked also. oh well, i learned a little bit about regular expressions today Smile