We created a home page at /node/123 and set this as the "Default front page" in "Basic site settings". This brings the user to the correct page when "/" is entered in a browser. This also creates:
<link rel="canonical" href="/node/123" />
which is not correct -- it should be href="/".

This behavior has a very negative side-effect, the page is listed by Google with a URL of https://dom.ain/node/123.

Comments

Greg Sims created an issue. See original summary.

timmillwood’s picture

Component: node system » system.module

I don't believe this is a node specific issue.

joshi.rohit100’s picture

I think its related to the node as this is rendered by NodeViewController but not sure if its an issue or not as same could be handled by some page_attachment_alter or node_view_alter().

raphaeltbm’s picture

Well, that seems to be an issue from the SEO point of view.

Is it Node or more globally Entity related, i'm not sure, but it's definitely managed by NodeVieController which loop on $node->uriRelationships() to add #attached things.

Don't really know if it should be fixed globally in the core. Don't know too, if it has to be fixed in the core, should it be handled in NodeViewController->view() or in Entity->toUrl() to cover every cases of entity which could be setted as a frontpage, to manage the canonical url of this specific entity correctly everywhere?

If the controller is updated, there is maybe a risk of side-effect because html_head_link is a special case which add data for html_head and for http_header attachments in HtmlResponseAttachmentsProcessor. Should be careful about the shortlink case managed in view() too.

If the entity class is updated, there is a high risk of side-effects and breakings, because lot of code/modules made tests and assumptions about the returned value of this function for an entity in a "canonical" rel context (search for toUrl('canonical'). The 'canonical' term / usage is not really the same there.

Maybe, to not break things, a mix of both, create a kind of extra frontpage_aware parameter managed in toUrl and use that in NodeViewController and all other contexts which needs the user/seo friendly URL?

I would add something like that in NodeViewController as a quickfix for the moment:

if ($rel=='canonical' && \Drupal::service('path.matcher')->matchPath('/' . $url->getInternalPath(),'<front>')) {
	$url = new Url('<front>');
}

edit: if not managed somewhere in the core, as said, this situation can be handled via an hook_page_attachments_alter() or installing the Metatag module which allow you to have more granular control, case per case.

raphaeltbm’s picture

I close this issue and will move my last comment in #1255092: url() should return / when asked for the URL of the frontpage.

It seems to be a bigger problem and i'm not really sure at what level it should be done to fix it globally and not have to manage the frontpage url case everywhere, everytime. It's a often forgotten case.

mdixoncm’s picture

Just stumbled over this issue - obviously there is a conversation around a proper fix - but for a quick fix, the metatag module has functionality to set a specific canonical and shortlink (and anything else) on the front page ...