How the hreflang is supposed to be built?

2019-03-03 08:32发布

问题:

My question is does the

<link rel="alternate" href="http://example.com/en" hreflang="en">
<link rel="alternate" href="http://example.com/it" hreflang="it">

should be like above an all pages or should be changed with the actual url of every page like:

<link rel="alternate" href="http://example.com/en/<?=$current;?>" hreflang="en">
<link rel="alternate" href="http://example.com/it/<?=$current;?>" hreflang="it">
<link rel="alternate" href="http://example.com/<?=$current;?>" hreflang="x-default">

回答1:

HTML5 defines:

If the alternate keyword is used with the hreflang attribute, and that attribute's value differs from the root element's language, it indicates that the referenced document is a translation.

So it’s for translated documents (i.e., pages), not sites.

http://example.com/en links to http://example.com/it,
http://example.com/en/hello links to http://example.com/it/ciao.