What is the best way to get the current URL for a canonical tag?

For SEO reasons I need to include a canonical tag, that points to the current action. For the following reasons, this would be needed:

  • Having 2 different URLs point to the same content
  • Using more than one domain
  • Having a bot generated URL for content, that usually only has one in the application (for example: https://example.com/?ref=https://devpick.io)

Our application has been a target of different third parties trying to influence our SEO by targeting our Server’s IP with a different domain or random bots adding ref query parameters to our URL on their sites. These issues can be fixed in multiple ways, the best general fix though, according to Google, is to use canonical links.

What would be the easiest way, to get the urlTo the current Action in the layout for the canonical tag?

Maybe adding an (optional) feature to IHP for a canonical tag using the url generated by urlTo Action or a recipe in the Guide would be a good idea.

1 Like

I think you should be able to get it by using something along these lines:

I believe that the currentPath is the canonical URL