如何解决从一个域到另一个域的URL转发,保留参数
如何配置我的短域以转发到我的主域,但保留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存储桶>“属性”>“静态网站托管”。
- 选择“重定向请求”
- 在“目标存储区或域”字段中,指定example.com
- 将“协议”字段保留为空。
在CloudFront中...
- 选择分布>“起源和起源组”
- 选择并编辑发行版
- 将“原始域名”更改为S3存储桶>“属性”>“静态网站托管”端点字段中指定的确切名称。看起来像:
http://example.org.s3-website-us-west-1.amazonaws.com
- 删除分发的“默认根对象”。