默认的发布位置为子域名(例: global.example.co.jp/en/),只需 1 条 DNS 记录即可运行。无论是子域名还是子目录,Google 的评价都是相同的,但如果出于品牌或 URL 设计的考虑, example.co.jp/en/ 希望像这样在自有域名下发布,只需在您的 CDN 或服务器上将语言路径转发(反向代理)至 Sotomuke 即可实现。
前提条件
- 已完成通过子域名(例:
global.example.co.jp)的发布。转发目标即为该主机名。 - 具备可在自有域名前端编写转发规则的环境(Cloudflare、各类 CDN、nginx/Apache、Next.js/Vercel、Netlify 等)。共享虚拟主机以及 STUDIO、Wix 等 SaaS 无法进行此设置,这种情况下请使用子域名。
- 日语页面仍由您的服务器照常提供,仅转发语言路径。
操作流程概览
- 在控制台的“发布设置”→“通过子目录发布”中保存发布 URL(例:
https://example.co.jp)。此后,canonical、hreflang、站点地图及语言切换的 URL 都将使用该域名。 - 请通过以下任一方法,将
/en/・/zh-Hans/・/ko/等所选语言的路径(包括其下所有内容)转发至global.example.co.jp。将 Host 标头也global.example.co.jp改写为是关键所在(Sotomuke 通过主机名识别网站)。 - 点击“确认转发”按钮,确认各语言的 URL 均由 Sotomuke 响应(响应中将带有
x-sotomuke-site标头)。 https://example.co.jp/robots.txt至Sitemap: https://global.example.co.jp/sitemap.xml这一行。只要是 robots.txt 中引用的站点地图,即使位于其他主机,Google 也会接受。请在 Search Console 中向 example.co.jp 的资源提交此站点地图。
方法A:Cloudflare(Origin Rules,无需编写代码)
如果域名处于 Cloudflare 代理(橙色云朵)之下,这是最简单的方法。请在 Rules → Origin Rules 中创建以下规则。
- 条件: URI Path starts with
/en/(按语言以 OR 追加。如果用表达式编写,则为(starts_with(http.request.uri.path, "/en/")) or (starts_with(http.request.uri.path, "/ko/"))) - Host header: Rewrite to
global.example.co.jp - DNS record: Override to
global.example.co.jp
如果通过 API 创建,则在 origin_rules 阶段的规则集中 action: "route"、action_parameters: { host_header: "global.example.co.jp", origin: { host: "global.example.co.jp" } } 添加。
方法B:Cloudflare Worker(需要更精细控制时)
export default {
async fetch(request) {
const url = new URL(request.url);
const langs = ["en", "zh-Hans", "ko"]; // ダッシュボードで選んだ言語
const lang = url.pathname.split("/")[1];
if (langs.includes(lang) || url.pathname === "/sitemap-sotomuke.xml") {
const target = new URL(url);
target.hostname = "global.example.co.jp"; // 公開ホスト名
if (url.pathname === "/sitemap-sotomuke.xml") target.pathname = "/sitemap.xml";
const res = await fetch(target.toString(), { headers: request.headers, cf: { cacheTtl: 300 } });
return new Response(res.body, res);
}
return fetch(request); // それ以外は元サイトへ
},
};
将 Worker 的路由 example.co.jp/* 设置为该值。/sitemap-sotomuke.xml 也一并转发后,即可在 robots.txt 中将其作为同一主机的站点地图填写。
方法C:nginx
location ~ ^/(en|zh-Hans|ko)/ {
proxy_pass https://global.example.co.jp;
proxy_set_header Host global.example.co.jp;
proxy_ssl_server_name on;
proxy_ssl_name global.example.co.jp;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /sitemap-sotomuke.xml {
proxy_pass https://global.example.co.jp/sitemap.xml;
proxy_set_header Host global.example.co.jp;
proxy_ssl_server_name on;
}
方法D:Apache(mod_proxy)
SSLProxyEngine On
ProxyPreserveHost Off
ProxyPassMatch "^/(en|zh-Hans|ko)/(.*)$" "https://global.example.co.jp/$1/$2"
ProxyPass "/sitemap-sotomuke.xml" "https://global.example.co.jp/sitemap.xml"
RequestHeader set Host "global.example.co.jp"
mod_proxy・mod_proxy_http・mod_ssl 是必需的。在租用服务器的 .htaccess 中通常无法使用。
方法E:Next.js / Vercel
// next.config.js
module.exports = {
async rewrites() {
return [
{ source: "/:lang(en|zh-Hans|ko)/:path*", destination: "https://global.example.co.jp/:lang/:path*" },
{ source: "/sitemap-sotomuke.xml", destination: "https://global.example.co.jp/sitemap.xml" },
];
},
};
如果静态网站托管在 Vercel 上,则在 vercel.json 的 rewrites 中写入相同内容。
方法F:Netlify
# _redirects
/en/* https://global.example.co.jp/en/:splat 200
/zh-Hans/* https://global.example.co.jp/zh-Hans/:splat 200
/ko/* https://global.example.co.jp/ko/:splat 200
/sitemap-sotomuke.xml https://global.example.co.jp/sitemap.xml 200
方法G:AWS CloudFront
在 Origin 中 global.example.co.jp(仅限 HTTPS,Origin protocol policy:HTTPS only)添加后,将 Behavior 的 Path pattern /en/* 等指向该 Origin。Cache policy 设置为转发 Query string,Origin request policy 设置为不转发 Host (由 CloudFront 发送 Origin 的主机名)。
确认要点
curl -sI https://example.co.jp/en/ | grep -i x-sotomuke-site中x-sotomuke-site: <スラッグ>如能返回,即表示转发成功。- 查询字符串(
?utm_source=等)请按原样转发。 - 转发规则必须在 WordPress 等的路由之前进行评估。如果原网站返回 404,请检查规则的顺序。
- 设置公开URL后,子域名一侧的URL(
global.example.co.jp/en/)仍可继续使用,但由于 canonical 指向贵公司域名,搜索结果中显示的将是贵公司域名的URL。 - 翻译页面的访问统计仍会照常显示在 Sotomuke 的控制面板中。
致网站制作公司
代理商方案可为每个网站进行相同的设置。如果您使用同一CDN运营大量网站,将语言路径的转发设置模板化后,新增网站只需几分钟即可完成。如需代为设置或验证,请联系我们。
