Improve ISC error 404 handling of URL with () bracket characters

Problem

In the system log, you will see many 404 errors of URL with ( ) bracket characters.

When people share/send a product URL to different forums or social platforms, the platforms may encode/convert %28 and %29 characters to ( and ) resulting in a broken link.

Solution

This mod will convert ( and ) to %28 and %29 and redirect. As a result, both URL formats will be served correctly.

In /class.404.php

Find

ISC_REDIRECTS::checkRedirect($_SERVER['REQUEST_URI']);

Add after

//MOD handle URL with () characters
if (preg_match('/[()]/', $_SERVER['REQUEST_URI']) AND preg_match('/.html/', $_SERVER['REQUEST_URI'])){
	$safeURL = str_replace("(","%28",$_SERVER['REQUEST_URI']);
	$safeURL = str_replace(")","%29",$safeURL);
	$safeURL = 'https://' .$_SERVER['HTTP_HOST'].$safeURL;
	header("HTTP/1.1 301 Moved Permanently");
	header("Location: $safeURL");
	exit;
}
//MOD END

Example:

Both URLs will lead to the product page.

Leave a Reply

Your email address will not be published. Required fields are marked *