【问题标题】:How does Google App Indexing handle https://www.example.com vs https://example.comGoogle App Indexing 如何处理 https://www.example.com 与 https://example.com
【发布时间】:2017-04-06 23:56:35
【问题描述】:

我刚刚为我网站的 Android 应用设置了 App Indexing,并按照 https://developers.google.com/app-indexing/android/test(使用 Android Studio 测试 URL)中指定的说明通过 https://www.example.com/testhttps://example.com/test 进行了一些测试

这是我的 Android 清单中的意图过滤器:

<intent-filter android:label="@string/filter_title_default">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="example.com"
          android:pathPrefix="/test" />
</intent-filter>

我注意到https://www.example.com/test 失败了,但https://example.com/test 没有。除了为 www.example.com/test 指定另一个意图过滤器之外,我该如何解决这个问题?

【问题讨论】:

    标签: android android-app-indexing


    【解决方案1】:

    据我所知,每个主机都应该添加到一个新的意图过滤器中。您可以参考此doc 了解更多信息。

    干杯, MB

    【讨论】:

      【解决方案2】:

      您可以为您的意图过滤器指定多个数据元素,为您需要处理您的活动的所有 URL。

      要处理指向您域的 www 和非 www 链接,您可以将您的意图过滤器更改为:

      <intent-filter android:label="@string/filter_title_default">
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="https"
                android:host="example.com"
                android:pathPrefix="/test" />
          <data android:scheme="https"
                android:host="www.example.com"
                android:pathPrefix="/test" />
      </intent-filter>
      

      或者要处理 example.com 和任何子域,您可以在主机的开头包含通配符:

      <intent-filter android:label="@string/filter_title_default">
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="https"
                android:host="example.com"
                android:pathPrefix="/test" />
          <data android:scheme="https"
                android:host="*.example.com"
                android:pathPrefix="/test" />
      </intent-filter>
      

      此外,如果您想匹配所有域 URL,则必须完全删除 pathPrefix 属性,因为将其设置为“/”不会按预期工作。

      【讨论】:

        猜你喜欢
        • 2016-01-16
        • 2011-07-06
        • 2011-08-12
        • 1970-01-01
        • 2016-04-29
        • 2015-09-25
        • 1970-01-01
        • 2020-09-24
        • 2014-03-04
        相关资源
        最近更新 更多