Closed dimayakovlev closed 3 years ago
Workaround is a compare if $_SERVER['REQUEST_URI']
starts with a result of find_url()
.
In PHP 8 added function str_starts_with()
: https://www.php.net/manual/en/function.str-starts-with.php
For older version of PHP:
function str_starts_with($haystack, $needle) {
return strpos($haystack , $needle) === 0;
}
This code can be used in index.php for correct comparison of requested and generated page urls:
if (getDef('GSCANONICAL', true)) {
if (strpos($_SERVER['REQUEST_URI'], find_url($url, $parent, 'relative')) !== 0) {
redirect(find_url($url, $parent));
}
}
Return of function
find_url()
compared with$_SERVER['REQUEST_URI']
. If requested URL contains query string client redirected to URL formed by functionfind_url()
.