过去,我已成功将 AngularJS 应用程序部署到 S3 并html5mode
启用,以允许无哈希 URL。
但是,对于我当前的项目,我需要将站点的 Angular 部分放入子目录 ( /app
) 中,但遇到了重大问题。
我已经尝试了一些事情,最值得注意的是以下内容,但它会导致重定向循环,而且我认为无论如何都无法使用否定规则匹配来避免这样的问题:
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>app/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>app/#</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Run Code Online (Sandbox Code Playgroud)
我还尝试通过将 404 引导到 app/(还有/app/#
, /app/index.html
, /app/index.html#
)来处理 404 ,但没有任何效果可以使我的应用程序按照我想要的方式工作。在我的 angular 应用程序中导致意外错误的示例:
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>mytest.s3-website-us-east-1.amazonaws.com</HostName>
<ReplaceKeyWith>app/index.html</ReplaceKeyWith>
</Redirect>
</RoutingRule>
</RoutingRules>
Run Code Online (Sandbox Code Playgroud)
我可以使用什么规则来让所有以/app
定向到开头的请求/app/#
?