404 Error Static Page Plugin - does not issue HTTP Status 404

Hi,

@ErwanBo, @Vitaliy

I refer to 404 error static page plugin and the forum posts listed there.

Unfortunately, the solution proposed and the plugin do not work as expected.

Unfortunately, this plugin does not issue a status 404 for the faultying URL, as it should.

You can test yourselves:

curl -I “https://emerging-neurologist.org/wrong_url343ezfz
HTTP/1.1 302 Found
Date: Thu, 08 Feb 2024 15:32:58 GMT
Server: Apache
Location: https://emerging-neurologist.org/404
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Robots-Tag: all
Content-Security-Policy: upgrade-insecure-requests
Content-Type: text/html; charset=utf-8

And the 404 page, to which is redirected, issues a HTTP Status 200.

This is bad for SEO.

Maybe somebody has an idea how to fix this? I have opened an issue on GitHub - ErwanBo/error404Plugin: redirect 404 errors to dedicated static page

Hello @mpbraendle

Thank you for pointing out this issue. I’ve reviewed the plugin code and believe I have addressed the problem for version 3.4.0. The updates have been applied to both emerging-neurologist.org and opus.u-paris.fr. Now, using your test, the response is as follows:

curl -I "https://emerging-neurologist.org/wrong_url343ezfz"
HTTP/1.1 404 Not Found
Date: Mon, 12 Feb 2024 17:44:59 GMT
Server: Apache
cache-control: no-store
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Robots-Tag: all
Content-Security-Policy: upgrade-insecure-requests
Content-Type: text/html; charset=utf-8 

Also now there is no more url redirection.

To make it work I had to replace :

public static function handle404() {
	header("Location: ".Application::get()->getRequest()->url(null, '404'));
	fatalError('404 Not Found');
}

by :

public static function handle404() {
	header("HTTP/1.1 404 Not Found");
	$templateMgr = TemplateManager::getManager(Application::get()->getRequest());
	$templateMgr->display('plugins/generic/error404/templates/frontend/pages/page404.tpl');
	exit;
}

A similar change can be made for the version 3_3_0 but I can’t test it at the moment as all my platforms are at version 3.4.x.

Thank you @ErwanBo,

works like a charm. See directly at Does not issue HTTP Status 404 · Issue #2 · ErwanBo/error404Plugin · GitHub what I’ve done for OJS 3.3.0-x

1 Like