CodeIgniter Forums

Full Version: URI Routing - only allow custom route?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.
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.