hrefang屬性對于谷歌SEO優化有什么幫助呢?
今天是平哥SEO學堂主講如何使用hrefang屬性助力多語言網站。因為合理使用hrefang屬性對管理和優化不同語言版本的網站,以及用戶體驗上,起到非常重要的效果。
一、hrefang原理
1、什么是hrefang
hrefang是一種html屬性,使用在link標簽里面,用來指定網頁的語言和目標區域。
簡單來說,就是當不同國家境內用戶訪問你的網站時,為了給客戶最好的用戶體驗,通過hrefang屬性設置,網站自動展示相應語言版本的頁面給用戶,讓客戶更好地訪問網站內容。
同時,你在不同地區進行Google搜索時,搜索結果展示的title和description以及URL地址都是當地語言。
2、hrefang工作原理
假設你的網址是:
www.example.com
那么你在德國使用Google搜索網站
或者進入網站時,
URL會顯示網站的德語網址為:
www.example.com/de/
或者de.example.com
具體的URL展示形式取決于你如何設置。
當你在美國使用Google搜索網站
或進入網站時,
URL會顯示網站的美式英語網址為:
www.example.com/en-us/
或者us.example.com
二、hrefang使用方式
hrefang使用方式有三種。
1、在html中使用
我們直接通過案例分析:
<linkrel="alternate"hreflang="lang_code"href="url_of_page"/>
①、案例中rel="alternate",代表該鏈接為此頁面的備用版本。
②、案例hreflang="lang_code"中的屬性值"lang_code"是舉例,指語言/區域版本代碼,由一個或兩個可選的值組成,兩個值之間用“-”符號分隔,并且此屬性在使用中,切記必須要填寫。
I、例如:
hrefang=“en”代表英語;
hrefang=“en-US”代表在美國境內使用的英語版本,即美式英語;
hrefang=“en-GB”代表在英國境內使用的英語版本,即英式英語;
道理類似于我們中文的簡體和繁體的意思,主要是便于用戶訪問瀏覽網站內容。
II、lang_code的值中,還可以使用x-default,主要是當網站的語言/區域與用戶的瀏覽器設置不匹配時,系統會使用保留值x-default,這時,我們可以使用x-default,讓用戶跳轉到相應的語言選擇頁面,然后進行選擇語言瀏覽。
使用方法如下:
<linkrel="alternate"href="https://example.com/en-gb"hreflang="en-gb"/>
<linkrel="alternate"href="https://example.com/en-us"hreflang="en-us"/>
<linkrel="alternate"href="https://example.com/en-au"hreflang="en-au"/>
<linkrel="alternate"href="https://example.com/country-selector"hreflang="x-default"/>
③、案例href="url_of_page"中,url_of_page這里是舉例,具體代表你網站相應語言/區域的url網址。
2、在http標頭中使用
這種方法,常用于非html文件,例如pdf,我們繼續通過案例來看:
Link:<https://de.example.com/file.pdf>;rel="alternate";hreflang="de",
<https://example.com/file.pdf>;rel="alternate";hreflang="en"
通過這種方法,我們就可以讓面向德語和英語的用戶訪問相對應的pdf文件。
3、在xml網站地圖中使用
這種方法可以把所有網址的所有語言和區域寫入進去,并且能快速讓Google知道。
下面我們引用官方案例來解釋:
假設添加下面三個頁面到xml網站地圖中:
I、以英語用戶為目標用戶:
www.example.com/english/page.html
II、以德語用戶為目標用戶:
www.example.de/deutsch/page.html
III、以瑞士境內的德語用戶為目標用戶:
www.example.de/schweiz-deutsch/page.html
使用方法如下:
<?xmlversion="1.0"encoding="UTF-8"?>
<urlsetxmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://www.example.com/english/page.html</loc>
<xhtml:linkrel="alternate"hreflang="de"href="https://www.example.de/deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="de-ch"href="https://www.example.de/schweiz-deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="en"href="https://www.example.com/english/page.html"/>
</url>
<url>
<loc>https://www.example.de/deutsch/page.html</loc>
<xhtml:linkrel="alternate"hreflang="de"href="https://www.example.de/deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="de-ch"href="https://www.example.de/schweiz-deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="en"href="https://www.example.com/english/page.html"/>
</url>
<url>
<loc>https://www.example.de/schweiz-deutsch/page.html</loc>
<xhtml:linkrel="alternate"hreflang="de"href="https://www.example.de/deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="de-ch"href="https://www.example.de/schweiz-deutsch/page.html"/>
<xhtml:linkrel="alternate"hreflang="en"href="https://www.example.com/english/page.html"/>
</url>
</urlset>
總結:
道理還是和hrefang的原理是一樣的,具體使用,就記住
<urlsetxmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">*解釋:把這個理解成規則,所有的內容要在規則里使用,并且有結束標簽。
<url>*解釋:這里理解成一個頁面url地址設置開始的標記,不需要填寫任何東西在此處,記住有開始就有結尾,對應好即可。
<loc>*解釋:這里是放網站原本url地址子元素,并且只能放一個url地址,有結尾,需注意對應!
<xhtml:linkrel="alternate"hreflang="語言/區域代碼1"href="相應的語言url地址1"/>*這里是使用方法,并且記住至少放一個
<xhtml:linkrel="alternate"hreflang="語言/區域代碼2"href="相應的語言url地址2"/>
...
</loc>*解釋:這是結尾,對應開頭loc標簽
</url>*解釋:這是結尾,對應開頭url標簽
</urlset>*解釋:這是結尾,對應開頭urlset標簽
今天就分享到這里,期待能幫助你!

