Magento 2 Developement

Magento 2: Canonical URL for homepage

Canonical url point exactly to canonical page for similar or duplicate pages ( Consolidate duplicate URLs ). I assume you are doing it to specify which URL that you want people to see in search results. Magento 2 has several options to set canonical url for homepage.

TIP: Check you current canonical URL using URL Inspection tool

Update Canonical URL via theme xml

Create or update following file for your current theme.
If you are not sure about this, check Content > Design > Configuration to find active theme.

app/design/frontend/<vendor>/<theme>/Magento_Cms/layout/cms_index_index.xml

After that run following commands in Magento 2 root folder:
php bin/magento setup:static-content:deployDeploys static view files
php bin/magento cache:cleanCleans cache type(s)

Update Canonical URL via Module

Module will contain 3 files. Basically 2 of them are mandatory for any module and 3rd is responsible for layout update. You need to update <vendor> and <module> to your values.

app/code/<vendor>/<module>/registration.php

app/code/<vendor>/<module>/etc/module.xml

app/code/<vendor>/<module>/view/frontend/layout/cms_index_index.xml

To install module run following commands in Magento 2 root folder:

If you want to disable or uninstall magento 2 module – check following links:
Magento 2: How to disable module
Magento 2: How to uninstall module

Leave a Reply

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