CodeIgniter, how to remove the controller name from the URL
Today I had a look to CodeIgniter, a PHP framework, which I find really good, and I got some problems on removing the controller name from the URL.. Luckily I found the solution in this forum, so I am going to share with you as well.. (here’s the link)
"Here is a way to remove the default controller name from the URLS
Say you have a default controller (home in our case), your URLs will be of this format
To get rid of the default controller name we use the routes file in the config folder. For the above example this would work
$route['^(about|contact|faq|resources)(/:any)?$'] = "home/$0";
What it does, is it checks if the any of the requested methods match the methods in your default controller. If they do it routes them to the default controller. You have to include all the methods in the default controller class. This is by re-routing by inclusion.
You can now use these URLS
Another solution would be by exclusion e.g.
$route['^(?!users|blog|controller3|controller4).*'] = "home/$0";
In the above solution we use names of other controllers and we re-route anything that doesn’t match to the default/home controller. You have to exclude the controller names so that their methods/URLS are not re-routed
I prefer the first one.”
I just copied what loosetops wrote.
Hope this help. Cheers!