SEO 与重定向
店面内置了免配置的 SEO 基础能力——每个端点都从请求中解析 origin,因此同一次部署可以同时正确服务 store-a.example.com 和 store-b.example.com。
robots.txt
Section titled “robots.txt”src/pages/robots.txt.ts 提供动态的 robots.txt:允许收录目录,
但排除账户、购物车、结账、订单和 API 路径,并指向同源 sitemap:
User-agent: *Allow: /Disallow: /account/Disallow: /cartDisallow: /checkoutDisallow: /orders/Disallow: /api/
Sitemap: https://<your-domain>/sitemap.xmlsitemap.xml
Section titled “sitemap.xml”src/pages/sitemap.xml.ts 在请求时根据实时商品目录生成 sitemap:
静态页面(首页、/products、about/contact/support)、分类页面,
以及每个在售商品的 /products/<category>/<slug> 页面(商品没有
分类时回退到 /products/<slug>)。它会对商品 API 分页遍历,保证
首页之外的内容也完整收录,并包含来自 created_at 的 lastmod。
品牌配置中 hiddenCategories 列出的分类 slug(如 uncategorized)
会被排除。
另有 src/pages/google-feed.xml.ts,基于同一商品目录生成 Google
Merchant Center XML 格式的 shopping feed。
商品结构化数据
Section titled “商品结构化数据”商品详情页在 HTML 中渲染 schema.org Product JSON-LD
(<script type="application/ld+json">):名称、去标签描述、图片、
规范 URL、SKU、品牌,以及带价格、币种、InStock/OutOfStock 库存
状态和 NewCondition 的 Offer。商品有评论时会包含聚合评分——
注意 WooCommerce 导入后评论可能会挂到 WPML 翻译商品上(见
迁移注意事项),在去重之前聚合
数字会分散在不同翻译副本上。
遗留 WooCommerce 重定向
Section titled “遗留 WooCommerce 重定向”迁移过来的店铺通过 301 保留旧 WooCommerce URL 权重:
/product/<slug>/→ 规范商品页。先查品牌内容的wooRedirects映射(重命名、合并或 WPML 翻译商品的静态旧 slug 优先于 API); 没有静态映射时,再通过商品 API 解析 slug 并 301 到其规范的/products/<category>/<slug>URL。未知 slug 返回 404。/product-category/<slug>/→ slug 是已知菜单分类时跳/products/<slug>,否则跳/products。
wooRedirects 映射位于品牌内容模块(src/lib/brand/<brand>.ts),
形式为 [编码后的WooSlug, 规范路径] 对。键是原始百分号编码的
WooCommerce post_name 小写形式——例如
old-%e6%97%a7%e6%ac%be-slug-…——因为 Astro 会在查表前解码
路由参数,重定向页面会在比较前重新编码。