URL 从一个域转发到另一个域,保留参数
URL forwarding from one domain to another, keeping the parameters
如何将我的短域配置为转发到我的主域但保留 url 路径?例如...
example.org/<keep-this>
应该重定向到 example.com/<keep-this>
目前,url 路径被丢弃,所以我看到了这个... example.org/<keep-this>
重定向到 example.com
注意:我的主域在 AWS S3/CloudFont/Route-53 上托管和管理。
分发配置如下:
"ETag": "<hidden>”,
"DistributionConfig": {
"CallerReference": "<hidden>",
"Aliases": {
"Quantity": 2,
"Items": [
"<hidden>",
"www.<hidden>"
]
},
"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "S3-<hidden>",
"DomainName": "<hidden>.s3.amazonaws.com",
"OriginPath": "",
"CustomHeaders": {
"Quantity": 0
},
"S3OriginConfig": {
"OriginAccessIdentity": ""
},
"ConnectionAttempts": 3,
"ConnectionTimeout": 10
}
]
},
"OriginGroups": {
"Quantity": 0
},
"DefaultCacheBehavior": {
"TargetOriginId": "S3-<hidden>",
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
]
}
},
"SmoothStreaming": false,
"Compress": true,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"CachePolicyId": "<hidden>"
},
"CacheBehaviors": {
"Quantity": 0
},
"CustomErrorResponses": {
"Quantity": 1,
"Items": [
{
"ErrorCode": 403,
"ResponsePagePath": "/error.html",
"ResponseCode": "404",
"ErrorCachingMinTTL": 60
}
]
},
"Comment": "",
"Logging": {
"Enabled": false,
"IncludeCookies": false,
"Bucket": "",
"Prefix": ""
},
"PriceClass": "PriceClass_All",
"Enabled": true,
"ViewerCertificate": {
"ACMCertificateArn": "<hidden>",
"SSLSupportMethod": "sni-only",
"MinimumProtocolVersion": "TLSv1.2_2019",
"Certificate": "<hidden>",
"CertificateSource": "acm"
},
"Restrictions": {
"GeoRestriction": {
"RestrictionType": "none",
"Quantity": 0
}
},
"WebACLId": "",
"HttpVersion": "http2",
"IsIPV6Enabled": true
}
}
要从 example.org/<keep-this>
重定向到 example.com/<keep-this>
,只需使用 S3 routing rules。
- 创建一个名为
example.org
的存储桶
- 开启“静态网站托管”
- 设置重定向规则如下
<RoutingRules>
<RoutingRule>
<Redirect>
<HostName>example.com</HostName>
</Redirect>
</RoutingRule>
</RoutingRules>
由于 S3 静态网站托管不支持 HTTPS,如果您需要 HTTPS,您应该在其前面放置一个 CloudFront 发行版。
我最终按照说明 here 在 S3 和 CloudFront 中解决了这个问题。这就是我所做的...
在 S3 中...
- 转到 example.org S3 存储桶>“属性”>“静态网站托管”。
- Select正在“重定向请求”
- 对于“目标存储桶或域”字段,指定 example.com
- 保持协议字段为空。
在 CloudFront 中...
- 选择分布>“来源和来源组”
- Select 并编辑分布
- 将“源域名”更改为在 S3 存储桶>“属性”>“静态网站托管”端点字段中指定的确切名称。看起来像:
http://example.org.s3-website-us-west-1.amazonaws.com
- 删除分发的“默认根对象”。
如何将我的短域配置为转发到我的主域但保留 url 路径?例如...
example.org/<keep-this>
应该重定向到 example.com/<keep-this>
目前,url 路径被丢弃,所以我看到了这个... example.org/<keep-this>
重定向到 example.com
注意:我的主域在 AWS S3/CloudFont/Route-53 上托管和管理。
分发配置如下:
"ETag": "<hidden>”,
"DistributionConfig": {
"CallerReference": "<hidden>",
"Aliases": {
"Quantity": 2,
"Items": [
"<hidden>",
"www.<hidden>"
]
},
"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "S3-<hidden>",
"DomainName": "<hidden>.s3.amazonaws.com",
"OriginPath": "",
"CustomHeaders": {
"Quantity": 0
},
"S3OriginConfig": {
"OriginAccessIdentity": ""
},
"ConnectionAttempts": 3,
"ConnectionTimeout": 10
}
]
},
"OriginGroups": {
"Quantity": 0
},
"DefaultCacheBehavior": {
"TargetOriginId": "S3-<hidden>",
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "redirect-to-https",
"AllowedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
],
"CachedMethods": {
"Quantity": 2,
"Items": [
"HEAD",
"GET"
]
}
},
"SmoothStreaming": false,
"Compress": true,
"LambdaFunctionAssociations": {
"Quantity": 0
},
"FieldLevelEncryptionId": "",
"CachePolicyId": "<hidden>"
},
"CacheBehaviors": {
"Quantity": 0
},
"CustomErrorResponses": {
"Quantity": 1,
"Items": [
{
"ErrorCode": 403,
"ResponsePagePath": "/error.html",
"ResponseCode": "404",
"ErrorCachingMinTTL": 60
}
]
},
"Comment": "",
"Logging": {
"Enabled": false,
"IncludeCookies": false,
"Bucket": "",
"Prefix": ""
},
"PriceClass": "PriceClass_All",
"Enabled": true,
"ViewerCertificate": {
"ACMCertificateArn": "<hidden>",
"SSLSupportMethod": "sni-only",
"MinimumProtocolVersion": "TLSv1.2_2019",
"Certificate": "<hidden>",
"CertificateSource": "acm"
},
"Restrictions": {
"GeoRestriction": {
"RestrictionType": "none",
"Quantity": 0
}
},
"WebACLId": "",
"HttpVersion": "http2",
"IsIPV6Enabled": true
}
}
要从 example.org/<keep-this>
重定向到 example.com/<keep-this>
,只需使用 S3 routing rules。
- 创建一个名为
example.org
的存储桶
- 开启“静态网站托管”
- 设置重定向规则如下
<RoutingRules>
<RoutingRule>
<Redirect>
<HostName>example.com</HostName>
</Redirect>
</RoutingRule>
</RoutingRules>
由于 S3 静态网站托管不支持 HTTPS,如果您需要 HTTPS,您应该在其前面放置一个 CloudFront 发行版。
我最终按照说明 here 在 S3 和 CloudFront 中解决了这个问题。这就是我所做的...
在 S3 中...
- 转到 example.org S3 存储桶>“属性”>“静态网站托管”。
- Select正在“重定向请求”
- 对于“目标存储桶或域”字段,指定 example.com
- 保持协议字段为空。
在 CloudFront 中...
- 选择分布>“来源和来源组”
- Select 并编辑分布
- 将“源域名”更改为在 S3 存储桶>“属性”>“静态网站托管”端点字段中指定的确切名称。看起来像:
http://example.org.s3-website-us-west-1.amazonaws.com
- 删除分发的“默认根对象”。