Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With AMP HTML, is it legitimate to set the link canonical href attribute to pound (#)?

Is it legitimate to set the canonical link to the pound symbol as shown below, or am I required to enter a physical page name?

<link rel="canonical" href="#">

When testing this, the pound setting does not generate a validation error (ala #development=1). In my scenario, the page using this layout file will not have an alternate "regular HTML" version. The only version will be the AMP HTML version.

For additional context, I'm experimenting with an MVC site that will use AMP HTML. To keep my layout file simple, I'd prefer to use the pound symbol rather than extracting the child page name and applying that to the href attribute. I know how to apply the URL to the partial view via code like so:

<link rel="canonical" href="@HttpContext.Current.Request.Url.AbsoluteUri">

I'm just curious if it's legitimate AMP HTML to use the pound symbol instead. Thank you.

like image 649
Ken Palmer Avatar asked Nov 02 '15 15:11

Ken Palmer


2 Answers

From the documentation:

Required markup

AMP HTML documents MUST:

  • contain a <link rel="canonical" href="$SOME_URL" /> tag inside their head that points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists.

So instead of using href="#", you should have it point to itself in order to stay consistent with the AMP specifications.

like image 106
not_a_bot Avatar answered Nov 15 '22 05:11

not_a_bot


Validation is evolving, the validator doesn't catch all issues today. The issue with using "#" or any relative URL is that when this document is served elsewhere, such as cdn.ampproject.org, that relative URL will no longer point to your intended canonical. You should instead use an absolute URL <link rel=canonical href="URL">.

like image 34
Gregable Avatar answered Nov 15 '22 04:11

Gregable