简体   繁体   中英

Codeigniter - Show 404 Page when User Types index.php

I need to show 404 page when user types index.php within the URL as:

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

I add this in routes.php $route['index.php/(:any)'] = 'custom404';

It didn't help; when user types http://localhost:8080/site_name/index.php/home home page shows up instead of 404 not found.

Any idea how to show 404 page when user types index.php within the URL?

My htaccess:

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

set default controller to custom404

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

or you could try this:

$route['index.php/^(.+)$'] = "custom404";

You can remove the index.php from your urls all together. It is on by default with CodeIgniter but you can remove it easily, just follow the guide here at their user guide: http://codeigniter.com/user_guide/general/urls.html

EDIT: it should also be known that the index.php in the url is not part of your controller, it is simply something put there by CodeIgniter so you cannot remove it by using your routes.

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