Codeigniter: send all requests that do not match a controller's name to the default controller Codeigniter: send all requests that do not match a controller's name to the default controller codeigniter codeigniter

Codeigniter: send all requests that do not match a controller's name to the default controller


You can use the codeigniter's URI routing for achieving this -

Insert this at the end of your route file -

$route[':any'] = 'path of the default controller';

All the other routes should be placed above the upper code.

Lets say the URL codeigniter encountered is -

http://fancysite.com/category

So firstly codeigniter will search if there is a controller named category.if it does not get that then it will check the route file to check that is there any route specified like this -

$route['category/:any'] = 'actual path';

If there is no such route specified in that case codeigniter will pass thisrequest to path of the default controller you have mentioned in your last lineof routes.

Even if the link contains sub-domain it doesn't matter the request will go tosame default controller.

Now you can insert logic for sub-domain handling or anything elsein the default controller.

You can even obtain the parameter 'category' in our url example taken which is in the URL using codeigniters URI helper class as below -

$this->uri->segment(1);