简体   繁体   中英

Codeigniter routing where there is no route

Currently I have a bunch of routes set up, and what I want to do is in the event of someone landing on my domain if its not a valid route I want them to go through a specific contoller. All the while retaining the welcome controller. for the domain itself. is this at all possible?

Use the $route['404_override'] in your application/config/routes.php ( bottom of the docs page ). It works just like any other rule (assing a controller/method to it. Inside that controller you can use the $this->uri->segment() or uri_string() or other input sources to decide what to do.

Just remember to send out 404 response headers with show_404() or otherwise if the request does in fact is looking for something non-existent.

Update

As it turns out, current (2.1 stable) branch doesn't seem to handle sub-directories for 404_override, in the Router class here , and here should try to check if there's a third segment with the subdir or not. Also, there's a pull request intended to fix this, not yet merged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM