本篇是系列文章,在看本文之前请先看:百度智能小程序接入自然搜索的步骤解析(1)和百度智能小程序接入自然搜索的步骤解析(2)。


第四步:配置 url 映射规则

url的映射规则定义的是小程序页面到 H5 页面的映射规则,百度搜索基于url 映射规则来计算百度智能小程序的排序权重以及和 H5 页面的去重处理等等,所以,配置 url 映射规则对百度智能小程序是很重要的。


增加 url-mapping 字段

在 app.json 增加 url-mapping 字段,配置智能小程序和对应的H5页面的 url 的映射规则,供搜索引擎在自然结果中将H5站url进行匹配和替换。

代码:

{
"pages": [
"path/to/smartapp/page1/page1",
"path/to/smartapp/page2/page2",
"path/to/smartapp/page3/page3"
],
"url-mapping": {
"path/to/smartapp/page1/page1":"/path/to/h5/page1?query1=${appquery1}&query2=${appquery2}",
"path/to/smartapp/page2/page2":"/path/to/h5/page2?query3=${appquery3}&query4=${appquery4}",
"path/to/smartapp/page3/page3":"/path/to/h5/page3?query5=${appquery5}&query6=${appquery6}"
}
}

需要注意这些:

1、url 映射规则通过字符串模板的方式进行定义,需要将 Web版的百度智能小程序 url 中的 query 部分,和字符串模板进行编译,生成正式的 url 实例才行。


2、如果百度智能小程序的路径和H5页面是一对一映射,则value为一个字符串;如果是一对多映射,则value为一个数组。

部分相对成熟的 Web 站点,同一内容的页面会泛化出不同的 url,且都被百度搜索正常收录,但是这些不同的 url 都对应同一个小程序路径,如果是这样,配置小程序路径到H5页面的映射规则,就需要1对多。


3、url 映射规则默认不包含 host 部分,具体的 host 需要开发者在上述步骤中的H5域名部分进行配置。url 映射规则也可包含 host 部分,要求 host 部分必须为在小程序平台的 H5 域名的子域。

不可省略 host 的情况:某些Web站点可能存在多个子域名,小程序的页面需要同时映射到多子域下的H5页面,这种场景下需要在上文中提到的H5域名区域出配置主域名,即可在url映射规则中配置H5子域。

可省略 host 的情况:小程序只需要映射到同一域名下的页面,只需要将该域名配置到上文提到的H5域名下,即可在 url 映射规则可省略 host。


联系电话:
1585150508*
QQ交谈:
小编
站长微信:
站长邮箱: service@qingjiuzhubei.com
31.16msRequest Duration2MBMemory UsageGET seoSchool/detail{id?}.htmlRouteAuth status
    • Booting (8.86ms)
    • Application (24.11ms)
      6 templates were rendered
      • site.zixun.seoDetail (resources/views/site/zixun/seoDetail.blade.php)9blade
        Params
        0
        cateAlls
        1
        newDetail
        2
        comment
        3
        hotnews
        4
        zuixinNews
        5
        xiangguan
        6
        t
        7
        d
        8
        k
      • layouts.site.layout (resources/views/layouts/site/layout.blade.php)21blade
        Params
        0
        obLevel
        1
        __env
        2
        app
        3
        device
        4
        isMobile
        5
        errors
        6
        cateAlls
        7
        newDetail
        8
        comment
        9
        hotnews
        10
        zuixinNews
        11
        xiangguan
        12
        t
        13
        d
        14
        k
        15
        __empty_1
        16
        __currentLoopData
        17
        hotnewsVal
        18
        loop
        19
        new
        20
        cateAll
      • layouts.site.top (resources/views/layouts/site/top.blade.php)21blade
        Params
        0
        obLevel
        1
        __env
        2
        app
        3
        device
        4
        isMobile
        5
        errors
        6
        cateAlls
        7
        newDetail
        8
        comment
        9
        hotnews
        10
        zuixinNews
        11
        xiangguan
        12
        t
        13
        d
        14
        k
        15
        __empty_1
        16
        __currentLoopData
        17
        hotnewsVal
        18
        loop
        19
        new
        20
        cateAll
      • layouts.site.bottom (resources/views/layouts/site/bottom.blade.php)21blade
        Params
        0
        obLevel
        1
        __env
        2
        app
        3
        device
        4
        isMobile
        5
        errors
        6
        cateAlls
        7
        newDetail
        8
        comment
        9
        hotnews
        10
        zuixinNews
        11
        xiangguan
        12
        t
        13
        d
        14
        k
        15
        __empty_1
        16
        __currentLoopData
        17
        hotnewsVal
        18
        loop
        19
        new
        20
        cateAll
      • common.upgrade_vip (resources/views/common/upgrade_vip.blade.php)21blade
        Params
        0
        obLevel
        1
        __env
        2
        app
        3
        device
        4
        isMobile
        5
        errors
        6
        cateAlls
        7
        newDetail
        8
        comment
        9
        hotnews
        10
        zuixinNews
        11
        xiangguan
        12
        t
        13
        d
        14
        k
        15
        __empty_1
        16
        __currentLoopData
        17
        hotnewsVal
        18
        loop
        19
        new
        20
        cateAll
      • kefu.kefu (resources/views/kefu/kefu.blade.php)21blade
        Params
        0
        obLevel
        1
        __env
        2
        app
        3
        device
        4
        isMobile
        5
        errors
        6
        cateAlls
        7
        newDetail
        8
        comment
        9
        hotnews
        10
        zuixinNews
        11
        xiangguan
        12
        t
        13
        d
        14
        k
        15
        __empty_1
        16
        __currentLoopData
        17
        hotnewsVal
        18
        loop
        19
        new
        20
        cateAll
      uri
      GET seoSchool/detail{id?}.html
      middleware
      web
      controller
      App\Http\Controllers\Site\ZixunController@seoSchoolDetail
      namespace
      App\Http\Controllers
      prefix
      /seoSchool
      where
      as
      seoSchoolDetail
      file
      app/Http/Controllers/Site/ZixunController.php:197-230
      8 statements were executed12.91ms
      • select * from `new_cates` where `pid` = '3' and `new_cates`.`deleted_at` is null1.7ms/app/Http/Controllers/Site/ZixunController.php:202zzshuju
        Metadata
        Bindings
        • 0. 3
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 12. /app/Http/Controllers/Site/ZixunController.php:202
        • 20. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 54. /public/index.php:53
      • select * from `news` where `news`.`id` = '26379' and `news`.`deleted_at` is null limit 1440μs/app/Http/Controllers/Site/ZixunController.php:203zzshuju
        Metadata
        Bindings
        • 0. 26379
        Hints
        • Use SELECT * only if you need all columns from table
        • LIMIT without ORDER BY causes non-deterministic results, depending on the query execution plan
        Backtrace
        • 14. /app/Http/Controllers/Site/ZixunController.php:203
        • 22. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 56. /public/index.php:53
      • select * from `new_cates` where `new_cates`.`id` in ('139') and `new_cates`.`deleted_at` is null340μs/app/Http/Controllers/Site/ZixunController.php:203zzshuju
        Metadata
        Bindings
        • 0. 139
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 19. /app/Http/Controllers/Site/ZixunController.php:203
        • 27. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 61. /public/index.php:53
      • select * from `news` where `news`.`deleted_at` is null order by `id` desc limit 10740μs/app/Http/Controllers/Site/ZixunController.php:205zzshuju
        Metadata
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 12. /app/Http/Controllers/Site/ZixunController.php:205
        • 20. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 54. /public/index.php:53
      • select * from `news` where `news`.`deleted_at` is null order by `published_at` desc limit 10690μs/app/Http/Controllers/Site/ZixunController.php:206zzshuju
        Metadata
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 12. /app/Http/Controllers/Site/ZixunController.php:206
        • 20. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 54. /public/index.php:53
      • select * from `news` where `newscate_id` = '139' and `news`.`deleted_at` is null order by `id` asc limit 104.15ms/app/Http/Controllers/Site/ZixunController.php:208zzshuju
        Metadata
        Bindings
        • 0. 139
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 12. /app/Http/Controllers/Site/ZixunController.php:208
        • 20. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 54. /public/index.php:53
      • update `news` set `browse` = `browse` + 1, `updated_at` = '2025-09-23 16:37:33' where `id` = '26379' and `news`.`deleted_at` is null4.52ms/app/Http/Model/News/News.php:170zzshuju
        Metadata
        Bindings
        • 0. 2025-09-23 16:37:33
        • 1. 26379
        Backtrace
        • 12. /app/Http/Model/News/News.php:170
        • 13. /app/Http/Controllers/Site/ZixunController.php:210
        • 21. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 55. /public/index.php:53
      • select * from `comments` where `news_id` = '26379'330μs/app/Http/Controllers/Site/ZixunController.php:214zzshuju
        Metadata
        Bindings
        • 0. 26379
        Hints
        • Use SELECT * only if you need all columns from table
        Backtrace
        • 12. /app/Http/Controllers/Site/ZixunController.php:214
        • 20. /vendor/silber/page-cache/src/Middleware/CacheResponse.php:38
        • 54. /public/index.php:53
        web
        array:2 [ "name" => "Guest" "user" => array:1 [ "guest" => true ] ]
        api
        array:2 [ "name" => "Guest" "user" => array:1 [ "guest" => true ] ]
          _token
          V2ErdkJECecR8cBssxG7lqdT4vikKR2z5gS245l5
          _previous
          array:1 [ "url" => "https://data.winndoo.cn/seoSchool/detail26379.html" ]
          _flash
          array:2 [ "old" => [] "new" => [] ]
          PHPDEBUGBAR_STACK_DATA
          []
          format
          html
          content_type
          text/html; charset=UTF-8
          status_text
          OK
          status_code
          200
          request_query
          []
          request_request
          []
          request_headers
          array:18 [ "cookie" => array:1 [ 0 => "Hm_lvt_767b4e8393ab59b402599f694cc019bd=1758616644; HMA...
          request_server
          array:42 [ "USER" => "apache" "HOME" => "/usr/share/httpd" "HTTP_COOKIE" => "Hm_lvt_767b4e8393...
          request_cookies
          array:4 [ "Hm_lvt_767b4e8393ab59b402599f694cc019bd" => null "HMACCOUNT" => null "Hm_lpvt_767b4...
          response_headers
          array:5 [ "cache-control" => array:1 [ 0 => "no-cache, private" ] "date" => array:1 [ ...
          path_info
          /seoSchool/detail26379.html
          session_attributes
          array:4 [ "_token" => "V2ErdkJECecR8cBssxG7lqdT4vikKR2z5gS245l5" "_previous" => array:1 [ "u...