R
R
rinatoptimus2021-08-04 16:16:01
PHP
rinatoptimus, 2021-08-04 16:16:01

How to spell canonical?

It is necessary that canonical be displayed only on the main page. Did it like this:

$currentUrl = "https://" . $_SERVER['SERVER_NAME']; 
if($currentUrl == "https://www.my-shop.com") {
  $APPLICATION->AddHeadString('<link rel="canonical" href="https://www.my-shop.com/" />');
}

As expected, canonical also appears on ...my-shop.com/cars, and on ...my-shop.com/bikes, and so on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rinatoptimus, 2021-08-16
@rinatoptimus

Did it like this:

$val = $APPLICATION->GetCurPageParam("", array_keys($_GET), false); 
$APPLICATION->SetPageProperty("canonical", $val);

P
Pavel Omelchenko, 2021-08-12
@pOmelchenko

You need a REQUEST_URI or use your app's router

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question