web.config重写规则在Blob存储中的Azure静态网站中不起作用 [英] web.config rewrite rule not working in Azure static website in blob storage

查看:78
本文介绍了web.config重写规则在Blob存储中的Azure静态网站中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure Blob存储中托管了一个页面React应用程序,但是却收到所请求的内容不存在.深度链接到页面时出现错误:

I have a single page React app hosted in Azure blob storage but am getting an The requested content does not exist. error when deep linking into a page:

我已在存储帐户中启用了静态网站选项:

文件都在$ web容器中的适当位置:

The files are all in place in the $web container:

这包括下面的 web.config 和重写规则,该规则应该让index.html处理所有路由:

This includes the following web.config with a rewrite rule that is supposed to let index.html handle all the routing:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

有人可以看到我哪里出问题了吗?

Can anyone see where I've gone wrong?

推荐答案

Azure Storage GPv2中的静态网站与Azure App Service不同.它仅托管这些静态Web文件,其中包括HTML/CSS/JavaScript文件,其他文件也可以在浏览器中处理,例如图像,robots.txt等.由于没有IIS,它无法处理服务器端脚本.因此,您的web.config文件没有任何意义来更改访问路由并属于IIS的服务器端脚本.

The static website in Azure Storage GPv2 is different from Azure App Service. It only hosts these static web files which include HTML/CSS/JavaScript files, other files can be handled in browser like images, robots.txt, etc. It has inability to process server-side scripts, due to there is not IIS. So your web.config file is no sense for it to change the access routing and be belong to server-side script for IIS.

实际上,您可以在Azure门户中看到这些单词.

Actually, you can see the words in Azure portal.

配置Blob服务以进行静态网站托管可让您在存储帐户中托管静态内容.网页可能包含静态内容和客户端脚本. Azure存储中不支持服务器端脚本. ,并参考

And refer to the Learn more link of Static website hosting in Azure Storage

与静态网站托管相比,最好使用Azure App Service托管依赖于服务器端代码的动态网站.

In contrast to static website hosting, dynamic sites that depend on server-side code are best hosted using Azure App Service.

如果需要URL重写功能,我建议为您的应用程序使用Azure App Service.

I recommended using Azure App Service for your app if requires the URL-rewrite feature.

这篇关于web.config重写规则在Blob存储中的Azure静态网站中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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