There is a site where you need to display
<link rel='canonical' href='http://site.ru/?cat=id'>
But the URL of the pages can be of 2 types:
http://site.ru/?cat=id&paged=id http://site.ru/?paged=id&cat=id id is a variable. Wrote just such a thing, but how it should still not work:
if (stripos(parse_url($_SERVER["REQUEST_URI"]),'cat') !== false) { if ( ((stripos(current(split('&',parse_url($_SERVER["REQUEST_URI"])['query'],'paged'))) != false)) & ((stripos(next(split('&',parse_url($_SERVER["REQUEST_URI"])['query'],'cat'))) != false)) ) { echo '<link rel="canonical" href="https://'.$_SERVER["HTTP_HOST"].'/?'.next(split('&',parse_url($_SERVER["REQUEST_URI"])['query'])).'" />'; } else { echo '<link rel="canonical" href="https://'.$_SERVER["HTTP_HOST"].'/?'.current(split('&',parse_url($_SERVER["REQUEST_URI"])['query'])).'" />'; } } Where is my mistake? Perhaps there is a way to make it easier? It would not be desirable to invent a redirect in Apache c paged=id&cat=id on cat=id&paged=id . PHP5
parse_url5 times, do you like to write very long and incomprehensible code? - teran<link href="http://site.ru/?cat={$_GET['cat']}">what? - teran