例如,我想将http://my-site.com/blog/post1重定向到http://blog.my-site.com/post1。我试图在其他地方找到答案,但总是朝着相反的方向(从子域重定向到路径)。
如果可能的话,我想完全用S3做这个,所以我们不必设置负载均衡器或代理服务器。在我们的案例中,https://my-site.com将部署在Cloudfront发行版后面的S3静态网站托管。有没有办法配置S3的重定向规则,以根据路径将请求重定向到子域?
答案 0 :(得分:0)
您重定向到子域的事实并不重要,并且基于他们的路径""几乎是如何在S3中重定向路由规则。
<RoutingRules>
<!-- example.com/blog -->
<RoutingRule>
<Condition>
<!-- no / goes here -->
<KeyEquals>blog</KeyEquals>
</Condition>
<Redirect>
<ReplaceKeyWith/> <!-- nothing -->
<Protocol>http</Protocol>
<HostName>blog.example.com</HostName>
</Redirect>
</RoutingRule>
<!-- example.com/blog/* -->
<RoutingRule>
<Condition>
<!-- note the / is after, not before, blog -->
<KeyPrefixEquals>blog/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith/> <!-- nothing -->
<Protocol>http</Protocol>
<HostName>blog.example.com</HostName>
</Redirect>
</RoutingRule>
</RoutingRules>