本文介绍了抓住所有控制器/路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想捕获传递给我的网络应用程序的每个单独的非现有网址,并为他们提供不提供404的视图,我该如何做?

If I want to catch every single non existing URL that was passed to my web application and serve them a view without serving a 404, how would I do that?

基本上,我需要记录基于这些命中的统计信息,但我需要通过提供内容,而不是404错误。

Essentially I need to record the statistics based on these hits, but I need to do it by serving content and not a 404 error.

就我可以从 application / config / routes.php 告诉我,我可以使用

As far as I can tell from application/config/routes.php, I could use

$route['default_controller'] = 'catchall';

但我需要的是我的实际网络应用程序。

but I need that for my actual web application.

我也可以使用

$route['404_override'] = 'catchall';

但我不想扔404s。

我尝试使用

$route['(:any)'] = '$1';

但我需要记录整个网址(例如,任何长度的段),而不仅仅是第一段。

but I need to record the entire URL (e.g. any length of segments), not just the first segment.

推荐答案

使用 $ route ['(:any)'] ='catchall_controller'。然后在您的控制器中,您可以使用 $ this-> uri-> segment(n)访问URI段。

Use $route['(:any)'] = 'catchall_controller'. Then in your controller you can access the URI segments using $this->uri->segment(n).

这篇关于抓住所有控制器/路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 02:19