0

I have setup 404 pages using cakephp controllers, and it is working fine when I try to go to a page that does not exist it comes back with http response 404 and the 404 page is displayed, but tools like woorank.com and PowerSeo always said that a custom 404 page is not defined?

Is there any thing I can do in the .htaccess file to make those tools know that I have 404 page defined? I have added the ErrorDocument 404 /404.html to .htaccess but still same error. Where do they look for the 404 page defined?

.htaccess file

<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
Tarkan
  • 45
  • 5

1 Answers1

3

From CakePHP Book:

By convention CakePHP will use App\Controller\ErrorController if it exists. Implementing this class can give you a configuration free way of customizing error page output.

Here is answer how to create ErrorController

next add in your router:

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'],
    );
});
Community
  • 1
  • 1
Salines
  • 5,674
  • 3
  • 25
  • 50