Android 為索引指定App內(nèi)容

2018-08-02 18:11 更新

編寫: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)頁中。

添加深度鏈接(Deep link)到你的Sitemap

要在你的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>

添加深度鏈接到你的網(wǎng)頁中

除了在你的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>

允許Google通過你的app抓取URL請求

一般來說,你可以通過使用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。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號