首页 文章

没有自定义404错误页面

提问于
浏览
0

我已经使用cakephp控制器设置了404页面,当我尝试访问不存在的页面时它正常工作它返回http响应404并显示404页面,但是像woorank.com和PowerSeo这样的工具总是说没有定义自定义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

1 回答

  • 3

    来自CakePHP Book:

    按照惯例,CakePHP将使用App \ Controller \ 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'],
        );
    });
    

相关问题