问题描述
按照Microsoft文档中的建议,我已经成功使用$web
容器在Azure Blob存储上建立了静态网站.另外,我为两者定义了index.html
,分别是索引文档名称"和错误文档名称". 这是因为我希望我的JavaScript应用程序处理404
响应.
I have succesfully set up a static website on Azure Blob storage using the $web
container as advised within the Microsoft documentation. In addition, I have defined index.html
for both the 'Index Document Name' and the 'Error Document Name'. This is because I want my JavaScript application to handle the 404
responses.
但是,当在Chrome中查看网络"标签时,尽管页面实际上在工作,但我仍看到正在为我请求的URL抛出404
.
However, when looking at the network tab in Chrome, I can see that a 404
is being thrown for the URL that I am requesting, despite the page actually working.
我的理论如下:
- Azure检查文件"是否存在
- 如果文件存在,则将其返回
- 如果文件不存在,它将抛出
404
并将URL重写为错误文档名称",即我的情况是index.html
(因此我的页面仍然可以使用)
- Azure checks to see if the 'file' exists
- If the file exists, it returns it
- If the file doesn't exist, it throws a
404
and rewrites the url to the 'Error Document Name' i.e.index.html
in my case (hence my pages still work)
我遇到的问题是我的URL是干净的URL,例如:
The problem I have is that my URLs are clean urls, for example:
/activities/some-slug
永远不会以文件形式存在,这只是告诉我的JavaScript应用程序将请求路由到哪里,即要加载的视图.
/activities/some-slug
is never going to exist as a file, this just tells my JavaScript application where to route the request i.e. what view to load.
请注意,页面可以起作用,因为它仍将404
错误路由到index.html
.
Just to be clear, the page does work because it is still routing 404
errors to index.html
.
如何告诉Azure blob将所有内容绝对路由到index.html
,并在必要时让我的应用抛出404
?
How can I tell Azure blob to just route absolutely everything to index.html
and let my app throw the 404
if necessary?
我们确实已经设置了Premium Verizon CDN,因为我最初不知道Azure Blob上的静态网站选项.如果CDN是最好的路线,请您能提供有关如何配置CDN以提供我所寻找的内容的说明吗?
We do have a Premium Verizon CDN set up already because I was not originally aware of the static website option on Azure Blob. If the CDN is the best route, please can you provide instructions on how to configure the CDN to provide what I am looking for?
我已经阅读了许多文章(特别是这),我认为可能存在各种解决方案,例如Azure Functions,Proxy,CDN等.也就是说,没有提供明确的说明来明确处理这些特定问题服务.
I have read numerous articles (specifically the comments in this one) and I believe that there may be various solutions i.e. Azure Functions, Proxy, CDN etc. That said, none provide clear instructions of what to actually do with those specific services.
我通常在AWS上工作,所以对所有Azure服务和可用配置都不熟悉.
推荐答案
我想我找到了解决方法
- 添加新规则
-
条件:URL文件扩展名
- Add a new rule
Condition: URL file extension
a.运算符:小于
b.扩展名:1
c.大小写转换:无转换
c. Case transform: No transform
[这基本上意味着所请求的URL没有文件(扩展名),但它是应用程序的路由,将由应用程序路由来处理]
[This basically means that the URL requested has no file (extension) but is a route of the app which will be taken care of by the app routing]
操作:URL重写
a.源模式:/
b.目的地:/index.html
b. Destination: /index.html
c.保留不匹配的路径:否
c. Preserve unmatched path: No
.
这篇关于在Azure Blob存储上使用静态网站选项托管SPA(干净的URL和深层链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!