[eluser]Yahtzie[/eluser]
I am developing a fairly large site which has quite a few different admin sections (all with different access ... but that's a different story). I recently struggled to configure a route to route everything EXCEPT my admin pages through the default controller. I tried using:
$route['web_admin'] = "web_admin";
$route['store_admin'] = "store_admin";
$route['blog_admin'] = "blog_admin";
$route[':any'] = "default_controller";
but this just routed everything (including all my admin pages) through the default controller.
After struggling many hours to write a regular expression to do this, I FINALLY figured it out, so I thought I'd share it in case anyone else ever wants to do this:
$route['(((?:.+)_(?!admin).+)|(?:\b[^_]+\b)|(?:\b[^_]*_\b)|(?:\b_[^_]*\b))'] = "default_controller";
Now, I'm sure not all your pages will have the format "something_admin", so here is a breakdown of the statement:
(
((?:.+)_(?!admin).+) <- any string of the format [anything]_[NOT "admin"][anything]
|(?:\b[^_]+\b) <- OR any string that doesn't contain an underscore
|(?:\b[^_]*_\b) <- OR any string that just has an underscore at the end
|(?:\b_[^_]*\b) <- OR any string that just has an underscore at the beginning
)
Hopefully this saves someone else a couple hours of headache.