CodeIgniter Forums

Full Version: regular expression trouble...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

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

El Forum

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

El Forum

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