I have a multistore website, but the seo is not working totally fine Like the title says: The website-url is fine, but product-url stays the same. But the product-url should be different for every store. In the .phtml is the follwing code:

<?php foreach ($block->getUrls() as $url): ?>
    <link rel="alternate" href="<?php echo $url['href'] ?>" hrefLang="<?php echo $url['hrefLang'] ?>"/>
<?php endforeach; ?>

And in the .php the code is:

foreach ($this->getAllStore() as $store) {
        $arr[] = [
            'href'     => str_replace($this->getStoreBaseUrl(), $store->getBaseUrl(), $this->getCanonicalUrl()),
            'hrefLang' => $this->setHreflang($store->getId())

The wrong output is now:

<link rel="alternate" href="http://testing.xxx.de/victor-blue.html" hrefLang="de-DE"/>
<link rel="alternate" href="https://www.xxx.nl/victor-blue.html" hrefLang="x-default"/>
<link rel="alternate" href="https://testing.xxx.be/victor-blue.html" hrefLang="nl-BE"/>
<link rel="alternate" href="https://testing.xxx.fr/victor-blue.html" hrefLang="fr-FR"/>
<link rel="alternate" href="https://testing.xxx.com/victor-blue.html" hrefLang="en-GB"/>

But I want the correct url from the correct store (the color is different as below):

<link rel="alternate" href="http://testing.xxx.de/victor-blue.html" hrefLang="de-DE"/>
<link rel="alternate" href="https://www.xxx.nl/victor-blauw.html" hrefLang="x-default"/>
<link rel="alternate" href="https://testing.xxx.be/victor-turkoois.html" hrefLang="nl-BE"/>
<link rel="alternate" href="https://testing.xxx.fr/victor-blue.html" hrefLang="fr-FR"/>
<link rel="alternate" href="https://testing.xxx.com/victor-bluw.html" hrefLang="en-GB"/>

Who can help me?

1 Answer 1


The problem comes from your getCanonicalUrl() function. Please check the return data in this function.

  • Thanks for your comment, but what should be different in the code: public function getCanonicalUrl() { $url = $this->getCurrentUrl(); if ($this->helperData->getDuplicateConfig('https_canonical')) { $url = str_replace('http:', 'https:', $url); } if ($this->getRequest()->getModuleName() == 'catalogsearch') { $position = strrpos($url, "catalogsearch"); $url = substr($url, 0, $position + 14); } return $url; } Aug 15, 2021 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.