"CodeIgniter 是否可以显示 404 页面错误的 index.php url?"
不,它不能。如果您输入错误index.php,那么您将不再使用/使用 CodeIgniter。
查看这个文件,你会看到index.php 正在构建所有内容,最后一行包含了 CodeIgniter.php 核心文件。
www.example.com/index.php/mistypedcontroller/mistypedfunction
上面的第一个是使用index.php,所以它是由CodeIgniter生成的。
www.example.com/mistyped.php/controller/function
第二个,因为它没有使用index.php,与 CodeIgniter 完全无关。
有没有办法在这里显示相同的 404 页面?
它必须是一个独立文件,并通过 Apache 的 .htaccess 文件使用 ErrorDocument 404 选项为您的特定服务器配置。
或者,如果你只是关注the documentation for removing the index.php from the URL,就不会出现上述情况;您损坏的 URL 示例将导致 CodeIgniter 404 错误,因为任何/每个 URL(指向不存在的文件)都被强制放入您的 index.php 文件中。
如果您的 Apache 服务器启用了 mod_rewrite,您可以使用带有一些简单规则的 .htaccess 文件轻松删除此文件。以下是此类文件的示例,使用“否定”方法,其中除了指定项目之外的所有内容都被重定向:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
在上面的示例中,任何 HTTP 请求,除了现有目录和现有文件都被视为对您的 index.php 文件的请求。