没有自定义404错误页面
问题描述:
我已经使用cakephp控制器设置404页面,并且当我尝试访问不存在的页面时它工作正常,它返回了http响应404并且404页面显示,但是像woorank.com和PowerSeo这样的工具总是说自定义404页面没有定义?没有自定义404错误页面
在.htaccess文件中,我可以做些什么来使这些工具知道我已经定义了404页面?我已经将ErrorDocument 404 /404.html添加到.htaccess,但仍然是相同的错误。他们在哪里寻找定义的404页面?如果存在
.htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.com [L,R=301]
</IfModule>
ExpiresActive On
ExpiresByType text/html "access plus 1 day"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
Header unset Pragma
Header unset ETag
FileETag None
ErrorDocument 404 /404.html
答
按照惯例CakePHP会使用应用程序\控制器\ ErrorController。实现这个类可以给你一个自定义错误页面输出的免费方式。
Here is answer如何创建ErrorController
下一个加在你的路由器:
CakePHP的2.x的:
Router::parseExtensions('html');
Router::connect(
'/404.html',
array('controller' => 'errors', 'action' => 'error404'),
);
CakePHP的3.X:
Router::scope('/', function ($routes) {
$routes->extensions(['html']);
$routes->connect(
'/404.html',
['controller' => 'Errors', 'action' => 'error404'],
);
});