Azure Web App Angular不重定向到www [英] Azure Web App Angular Not redirecting to www
问题描述
我的web.config中包含以下内容
I have the following in my web.config
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<rewrite>
<rules>
<rule name="Angular" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true"/>
</rule>
<rule name="Redirect to www" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^mydomain.com$" />
</conditions>
<action type="Redirect"
url="{MapProtocol:{HTTPS}}://www.mydomain.com/{R:1}" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapProtocol">
<add key="on" value="https" />
<add key="off" value="http" />
</rewriteMap>
</rewriteMaps>
</rewrite>
</system.webServer>
</configuration>
我的angular.json文件中有以下内容
I have the following in my assets in my angular.json
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
但是我的应用程序不会重定向.
But my app does not redirect.
问题是我为www.mydomain.com建立了由应用服务托管的证书设置
The issues is i have a App Service managed cert setup for www.mydomain.com
我有两个自定义域设置 www.mydomain.com(这使我可以将绑定添加到应用服务证书) mydomain.com(未绑定,因为我无法添加证书)
I have two custom domains setup www.mydomain.com (this one allows me to add the binding to the app service cert) mydomain.com (is unbound as I cant add a cert)
所以我想我可以通过重定向来解决它,以始终访问www.但它似乎不起作用
So I thought I could fix it with the redirect to always go to www. but it does not seem to work
推荐答案
更新
您可以RewriterConfig
在web.config文件中设置url重写功能.更多详细信息,请参见帖子
You can RewriterConfig
to set url rewrite function in web.config file. More details you can see my answer in anothor post .
重要
App Service集成的Web服务器不能完全控制,这是PaaS产品的属性之一.
The Web Server integrated by App Service cannot have full control, which is one of the attributes of PaaS products.
应用程序服务只能使用IIS的某些功能.需要在/site/wwwroot
下的web.config文件(即您开发的项目的根目录)中对其进行配置.
所有可用的IIS功能只能通过web.config
文件进行配置.
App Service can only use some functions of IIS. It needs to be configured in the web.config file under /site/wwwroot
(that is, the root directory of the project you develop).
All available IIS functions can only be configured through the web.config
file.
解决方案:
•尝试在Web配置文件中添加重定向规则.如果失败,则只能使用应用程序网关的重写功能.
• Try to add redirect rule in the web config file. If it fails, you can only use the rewrite feature of the application gateway.
•以下是一些有关重写功能的Application Gateway文档,供您参考.
• The following are some documents of Application Gateway about rewrite feature for your reference.
这篇关于Azure Web App Angular不重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!