Say I have an “Articles” controller, but I want it to appear as a subfolder (for example, “blog / articles”), I can add a route as follows:
$route['blog/articles'] = 'articles';
$route['blog/articles/(:any)'] = 'articles/$1';
This works great, the only problem is that example.com/articlesthey example.com/blog/articlesuse the article controller and thus allow the same content. Is there any way to prevent this?
To add a bit more clarity in case people don't understand:
- In this example, I don’t have a “blog” controller, but I want “articles”, etc. displayed in this subfolder (this is organization).
- I may have a blog controller with an “article” function, but I will probably have a bunch of “subcontrollers” and you want to separate the functionality (otherwise I could get 30+ functions for individual objects in the blog controller).
- I want
example.com/articles404 to be returned, as this is not a valid URL, example.com/blog/articlesthere is.
source
share