【问题标题】:URL forwarding from one domain to another, keeping the parameters从一个域到另一个域的 URL 转发,保留参数
【发布时间】:2026-01-26 14:10:01
【问题描述】:

如何配置我的短域以转发到我的主域但保留 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
    }
}

【问题讨论】:

  • 您需要展示您的 CloudFront 配置,包括来源和行为。请使用aws cloudfront get-distribution-config 的输出更新您的问题(或者,如果您使用的是 CloudFormation 或 Terraform,请使用资源定义)。
  • 您说的是 URL parameters 还是 paths?你说参数,但你的例子显示了一个路径。
  • 感谢您的区别 - 只是将其从“参数”更改为“路径”。
  • 谢谢@Parsifal——刚刚添加了每个 get-distribution-config 的输出——我用 隐藏了任何可能独特或敏感的东西,只是为了确保我没有做任何危险的事情!

标签: amazon-web-services web url amazon-s3 dns


【解决方案1】:

要从example.org/&lt;keep-this&gt; 重定向到example.com/&lt;keep-this&gt;,只需使用S3 routing rules

  1. 创建一个名为example.org的存储桶
  2. 开启“静态网站托管”
  3. 如下设置重定向规则
<RoutingRules>
  <RoutingRule>
      <Redirect>
        <HostName>example.com</HostName>
      </Redirect>
  </RoutingRule>
</RoutingRules>

由于 S3 静态网站托管不支持 HTTPS,如果您需要 HTTPS,您应该在其前面放置一个 CloudFront 发行版。

【讨论】:

    【解决方案2】:

    我最终按照here 的说明在 S3 和 CloudFront 中解决了这个问题。这就是我所做的......

    在 S3 中...

    1. 转到 example.org S3 存储桶 >“属性”>“静态网站托管”。
    2. 选择“重定向请求”
    3. 对于“目标存储桶或域”字段,指定 example.com
    4. 将“协议”字段保留为空。

    在 CloudFront...

    1. 选择分布 > “起源和起源组”
    2. 选择和编辑分布
    3. 将“源域名”更改为在 S3 存储桶 >“属性”>“静态网站托管”端点字段中指定的确切名称。看起来像:http://example.org.s3-website-us-west-1.amazonaws.com
    4. 删除分发的“默认根对象”。

    【讨论】:

      最近更新 更多