“可以CodeIgniter显示404错误类型index.php网址的页面?”
不,它不能。如果您输错index.php
,那么您不再在/使用CodeIgniter。
看看这个文件,你会发现index.php
正在构建一切,最后一行是包含CodeIgniter.php核心文件。
www.example.com/index.php/mistypedcontroller/mistypedfunction
这第一个以上是使用index.php
,所以它是由笨生成。
www.example.com/mistyped.php/controller/function
这第二个,因为它不使用index.php
,绝对没有做笨。
有没有办法在这里显示相同的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
文件的请求。
好的,我现在明白了。谢谢 – daxu
@daxu,不客气。请“接受”我的回答。谢谢。 – Sparky