[英]Codeigniter - Show 404 Page when User Types index.php
当用户在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]
将默认控制器设置为custom404
$route['default_controller'] = "custom404";
或者您可以尝试以下方法:
$route['index.php/^(.+)$'] = "custom404";
您可以一起从网址中删除index.php。 默认情况下,它与CodeIgniter一起处于启用状态,但您可以轻松删除它,只需按照其用户指南中的指南进行操作即可: http : //codeigniter.com/user_guide/general/urls.html
编辑:还应该知道url中的index.php不是您的控制器的一部分,它只是CodeIgniter放在其中的内容,因此您不能使用路由将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.