1

当用户在 URL 中键入 index.php 时,我需要显示 404 页面:

http://localhost:8080/site_name/index.php/home

我在 routes.php 中添加了这个$route['index.php/(:any)'] = 'custom404';

它没有帮助;当用户键入http://localhost:8080/site_name/index.php/home主页时显示而不是 404 未找到。

知道当用户在 URL 中键入 index.php 时如何显示 404 页面吗?

我的 htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site_name/index.php/$1 [L]
4

2 回答 2

0

将默认控制器设置为 custom404

$route['default_controller'] = "custom404";

或者你可以试试这个:

$route['index.php/^(.+)$'] = "custom404";
于 2012-08-09T18:33:28.983 回答
0

您可以一起从您的网址中删除 index.php。CodeIgniter 默认启用,但您可以轻松删除它,只需按照其用户指南中的指南进行操作:http: //codeigniter.com/user_guide/general/urls.html

编辑:还应该知道 url 中的 index.php 不是你的控制器的一部分,它只是 CodeIgniter 放在那里的东西,所以你不能通过使用你的路由来删除它。

于 2012-08-09T18:42:37.023 回答