CodeIgniter Forums
URI Routing - only allow custom route? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: URI Routing - only allow custom route? (/showthread.php?tid=65153)



URI Routing - only allow custom route? - mr_pablo - 05-06-2016

I have some routing setup e.g. I use an `auth` controller for login/logout stuff etc. and I am routing the methods to nicer URLs to remove the `auth` wording, so `auth/logout` simply becomes `logout`.

However, you can still access `auth/logout` if you know the URL exists.

Is there a way to force the custom routes to be the only way to access that particular Controller and Method?


RE: URI Routing - only allow custom route? - kilishan - 05-06-2016

There's nothing built into the system currently to handle that. However, you can use a regular expression to catch all routes not defined and route them to a junk page that will error out. Not ideal, but will work. Something like:

Code:
$route['(.+)'] = 'something';

Just make sure that's the very last route in your system.


RE: URI Routing - only allow custom route? - cartalot - 05-06-2016

Quote:However, you can still access `auth/logout` if you know the URL exists.

* You can  put something in the constructor of the logout controller to catch this,
and redirect them before any of the methods can be called. Or you can do something similar in the index method if its easier.