Amazon S3的重定向规则 - preserve查询参数 [英] Amazon S3 Redirect Rule - Preserve Query Params

查看:765
本文介绍了Amazon S3的重定向规则 - preserve查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到<一个href="http://stackoverflow.com/questions/23993675/amazon-s3-redirect-rule-get-data-is-missing">Amazon S3重定向规则 - GET按照接受的答案我的查询参数仍没有被preserved数据丢失但在

我有一个使用反应并做出反应路由器一个网站,这意味着我有一个加载相同的HTML和JS,然后JS计算出该应用程序的一部分来加载有基于URL的几个网址。

I have a site that uses React and React Router, meaning I have several URLs that load identical HTML and JS and then the JS figures out which part of the app to load based on the URL.

例如:

/ foo,那么/条,/巴兹都应该加载的index.html,它加载bundle.js。然后bundle.js观察URL和路线作出反应的一些成分(也bundle.js)。

/foo, /bar, /baz all should load index.html, which loads bundle.js. Then bundle.js observes the URL and routes to some React component (also in bundle.js).

但是没有富,酒吧,巴兹或文件存在在S3中,只有index.html的。我想做的是当我得到一个404重定向到/#!/ {} URL(如/富重定向到/#!/富)。这能与我的重定向规则(下图)。不过,我也希望把查询参数与我(如/富?平=乒乓球重定向到/#!/富?平=乒乓),而是/富?平=乒乓球只是重定向到/#!/ foo中。

However no foo, bar, or baz file exists in S3, only index.html. What I want to do is when I get a 404, redirect to /#!/{URL} (eg. /foo redirects to /#!/foo). This works fine with my redirect rule (below). However, I also want to bring query params with me (eg. /foo?ping=pong redirects to /#!/foo?ping=pong) but instead /foo?ping=pong just redirects to /#!/foo.

下面是我的重定向规则:

Here are my redirect rules:

<RoutingRules>
    <RoutingRule>
        <Condition>
            <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
        </Condition>
        <Redirect>
            <Protocol>http</Protocol>
            <HostName>www.mydomain.com</HostName>
            <ReplaceKeyPrefixWith>#!/</ReplaceKeyPrefixWith>
        </Redirect>
    </RoutingRule>
</RoutingRules>

这是一些方法,我可以做到这一点任何想法?理想的情况下,而不必每次去改变的东西在S3 / CloudFront的我添加了新的一页?

Any ideas on some way I can achieve this? Ideally without having to go change something in S3/CloudFront every time I add a new page?

推荐答案

问题是,我有原产地设立CloudFront的不转发查询字符串,所以当S3得到它会重定向不正确的查询参数的要求。您可以在CloudFront的>行为此设置>转发查询字符串。

The problem was that I had the origin set up in CloudFront not to forward Query Strings so when S3 got the request it would redirect properly without the query params. You can find this setting in CloudFront > Behaviors > Forward Query Strings.

这篇关于Amazon S3的重定向规则 - preserve查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆