You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多语言电商站更换域名:如何编写分场景301重定向规则?

WordPress电商域名迁移:分场景301重定向方案(含多语言适配)

301永久重定向是迁移域名时传递SEO权重的标准方式,以下是针对你的需求(分产品/分类/标签定向、适配多语言子目录、非全局重定向)的具体实现方案,优先推荐性能更优的Nginx服务器端配置,同时提供Apache .htaccess方案。


Apache (.htaccess) 实现

将以下规则放在旧域名根目录的.htaccess文件顶部(确保Apache已开启mod_rewrite和AllowOverride All):

基础配置

RewriteEngine On
RewriteBase /

1. 多语言产品页重定向

匹配默认语言(无前缀)、/ca/、/es/前缀的产品路径,跳转至新域名对应地址:

# 默认语言产品页
RewriteRule ^product/(.+)$ https://newdomain.com/product/$1 [R=301,L]

# /ca/语言产品页
RewriteRule ^ca/product/(.+)$ https://newdomain.com/ca/product/$1 [R=301,L]

# /es/语言产品页
RewriteRule ^es/product/(.+)$ https://newdomain.com/es/product/$1 [R=301,L]

2. 多语言分类页重定向

假设分类路径为/category/,规则如下:

# 默认语言分类页
RewriteRule ^category/(.+)$ https://newdomain.com/category/$1 [R=301,L]

# /ca/语言分类页
RewriteRule ^ca/category/(.+)$ https://newdomain.com/ca/category/$1 [R=301,L]

# /es/语言分类页
RewriteRule ^es/category/(.+)$ https://newdomain.com/es/category/$1 [R=301,L]

3. 多语言标签页重定向

假设标签路径为/tag/,规则如下:

# 默认语言标签页
RewriteRule ^tag/(.+)$ https://newdomain.com/tag/$1 [R=301,L]

# /ca/语言标签页
RewriteRule ^ca/tag/(.+)$ https://newdomain.com/ca/tag/$1 [R=301,L]

# /es/语言标签页
RewriteRule ^es/tag/(.+)$ https://newdomain.com/es/tag/$1 [R=301,L]

4. 单独页面重定向

针对非产品/分类/标签的页面,按具体路径单独配置:

# 默认语言单独页面示例
RewriteRule ^about-us/$ https://newdomain.com/about-us/ [R=301,L]
RewriteRule ^contact/$ https://newdomain.com/contact/ [R=301,L]

# 多语言单独页面示例
RewriteRule ^ca/about-us/$ https://newdomain.com/ca/about-us/ [R=301,L]
RewriteRule ^es/contacto/$ https://newdomain.com/es/contacto/ [R=301,L]

关键注意事项

  • 规则顺序优先级:产品/分类/标签规则 > 单独页面规则,避免被兜底规则覆盖
  • 测试阶段可将R=301改为R=302(临时重定向),确认跳转正确后再换回301,防止浏览器缓存错误规则
  • 确保旧域名服务器允许.htaccess生效(需在Apache虚拟主机配置中设置AllowOverride All)

Nginx 服务器端实现(性能更优)

Nginx的重定向规则直接写在服务器配置中,性能优于Apache的.htaccess,适合大流量电商站点。在旧域名的Nginxserver块内添加以下规则:

1. 产品/分类/标签批量重定向

# 产品页重定向
rewrite ^/product/(.+)$ https://newdomain.com/product/$1 permanent;
rewrite ^/ca/product/(.+)$ https://newdomain.com/ca/product/$1 permanent;
rewrite ^/es/product/(.+)$ https://newdomain.com/es/product/$1 permanent;

# 分类页重定向
rewrite ^/category/(.+)$ https://newdomain.com/category/$1 permanent;
rewrite ^/ca/category/(.+)$ https://newdomain.com/ca/category/$1 permanent;
rewrite ^/es/category/(.+)$ https://newdomain.com/es/category/$1 permanent;

# 标签页重定向
rewrite ^/tag/(.+)$ https://newdomain.com/tag/$1 permanent;
rewrite ^/ca/tag/(.+)$ https://newdomain.com/ca/tag/$1 permanent;
rewrite ^/es/tag/(.+)$ https://newdomain.com/es/tag/$1 permanent;

2. 单独页面重定向

# 默认语言单独页面示例
rewrite ^/about-us/$ https://newdomain.com/about-us/ permanent;
rewrite ^/contact/$ https://newdomain.com/contact/ permanent;

# 多语言单独页面示例
rewrite ^/ca/about-us/$ https://newdomain.com/ca/about-us/ permanent;
rewrite ^/es/contacto/$ https://newdomain.com/es/contacto/ permanent;

关键注意事项

  • 修改配置后重启Nginx生效:sudo systemctl restart nginx
  • permanent对应301永久重定向,测试阶段可用redirect(302临时重定向)
  • 规则需放在server块内location /之前,确保优先匹配

SEO 验证要点

  • 使用HTTP状态码检查工具确认所有跳转返回301状态码
  • 在搜索引擎站长平台提交新域名站点地图,并设置旧域名到新域名的站点转移
  • 监控流量和排名变化,确保权重正常传递

内容的提问来源于stack exchange,提问作者Sascha Ehrentraut

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 12:01:12