W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
編寫:Lin-H - 原文: http://developer.android.com/training/app-indexing/enabling-app-indexing.html
Google的網(wǎng)頁爬蟲機器(Googlebot)會抓取頁面,并為Google搜索引擎建立索引,也能為你的Android app內(nèi)容建立索引。通過選擇加入這一功能,你可以允許Googlebot通過抓取在Google Play Store中的APK內(nèi)容,為你的app內(nèi)容建立索引。要指出哪些app內(nèi)容你想被Google索引,只需要添加鏈接元素到現(xiàn)有的Sitemap文件,或添加到你的網(wǎng)站中每個頁面的<head>
元素中,以相同的方式為你的頁面添加。
你所共享給Google搜索的深度鏈接必須按照下面的URI格式:
android-app://<package_name>/<scheme>/<host_path>
構成URI的各部分是:
package_name 代表在Google Play Developer Console中所列出來的你的APK的包名。
scheme 匹配你的intent filter的URI方案。
host_path 找出你的應用中所指定的內(nèi)容。
下面的幾節(jié)敘述如何添加一個深度鏈接URI到你的Sitemap或網(wǎng)頁中。
要在你的Sitemap中為Google搜索app索引(Google Search app indexing)添加深度鏈接的注解,使用<xhtml:link>
標簽,并指定用作替代URI的深度鏈接。
例如,下面一段XML代碼向你展示如何使用<loc>
標簽指定一個鏈接到你的頁面的鏈接,以及如何使用<xhtml:link>
標簽指定鏈接到你的Android app的深度鏈接。
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>example://gizmos</loc>
<xhtml:link
rel="alternate"
href="android-app://com.example.android/example/gizmos" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" />
</url>
...
</urlset>
除了在你的Sitemap文件中,為Google搜索app索引指定深度鏈接外,你還可以在你的HTML標記網(wǎng)頁中給深度鏈接添加注解。你可以在<head>
標簽內(nèi)這么做,為每一個頁面添加一個<link>
標簽,并指定用作替代URI的深度鏈接。
例如,下面的一段HTML代碼向你展示如何在頁面中指定一個URL為example://gizmos
的相應的深度鏈接。
<html>
<head>
<link rel="alternate"
href="android-app://com.example.android/example/gizmos" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" />
...
</head>
<body> ... </body>
一般來說,你可以通過使用robots.txt文件,來控制Googlebot如何抓取你網(wǎng)站上的公開訪問的URL。當Googlebot為你的app內(nèi)容建立索引后,你的app可以把HTTP請求當做一般操作。但是,這些請求會被視為從Googlebot發(fā)出,發(fā)送到你的服務器上。因此,你必須正確配置你的服務器上的robots.txt
文件來允許這些請求。
例如,下面的robots.txt
指示向你展示,如何允許你網(wǎng)站上的特定目錄(如 /api/
)能被你的app訪問,并限制Googlebot訪問你的網(wǎng)站上的其他目錄。
User-Agent: Googlebot
Allow: /api/
Disallow: /
學習更多關于如何修改robots.txt
,來控制頁面抓取,詳見Controlling Crawling and Indexing Getting Started。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: