用户访问 mumu.top 跳转到 www.mumu.top 实现的方式
1. nginx上的实现方式
server {listen 80;server_name mumu.top;return 301 https://www.mumu.top;
}
2. aws上的实现方式
实现 原理其实使用 cloudfront 的 Distributions+function 当nginx用。具体操作如下:
- 1.创建单独的Distributions并绑定 wodetian.top域名
- 2.创建function
function handler(event) {var response = {statusCode: 301,statusDescription: "Moved Permanently",headers: {"location": { "value": "https://www.mumu.top" }}};return response;
}
- 3.将function绑定到Behavior
- 4.将wodetian.top解析到 Distributions cname上
这一步可以在本地hosts解析 验证没问题之后再做。 - 5.验证
curl -I mumu.top
HTTP/1.1 301 Moved Permanently
Server: CloudFront
Date: Tue, 18 Mar 2025 04:07:47 GMT
Content-Length: 0
Connection: keep-alive
Location: https://www.mumu.top
X-Cache: FunctionGeneratedResponse from cloudfront
Via: 1.1 d4555cc532101371fed7b03db24c29be.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: SIN52-P1
X-Amz-Cf-Id: XAuL-J7MNGfbVcPVizpIHFr1NhG7sqbW9OS5OhRSwUTPo5DPgKlT3Q==