创建重定向规则,将 HTTPS 请求从根域名(也称为 “apex” 或 “naked” 域名)转发到 WWW 子域名。
本示例创建一条重定向规则,将 HTTPS 请求从根域名(example.com)转发到 WWW 子域名(www.example.com),同时保留原始路径和查询字符串。
When incoming requests match(当传入请求匹配时)
- Wildcard pattern(通配符模式)
- Request URL(请求 URL):
https://example.com/*
- Request URL(请求 URL):
Then(然后)
- Target URL(目标 URL):
https://www.example.com/${1} - Status code(状态码):301
- Preserve query string(保留查询字符串):已启用
此规则确保仅将来自根域名的 HTTPS 请求重定向到 WWW 子域名,其他请求(例如 HTTP 或发往其他子域名的请求)保持不变。
例如,该重定向规则将执行以下重定向:
| Request URL | Target URL | Status code |
|---|---|---|
https://example.com/products/ |
https://www.example.com/products/ |
301 |
https://store.example.com/products/ |
(unchanged) | n/a |
https://example.com/admin/?logged_out=true |
https://www.example.com/admin/?logged_out=true |
301 |
http://example.com/?all_items=true |
(unchanged) | n/a |
http://www.example.com/admin/ |
(unchanged) | n/a |
在部署规则之前,请务必将 example.com 替换为你的实际主机名。