Azure Web App Angular Not redirecting to www

帅比萌擦擦* 提交于 2020-05-17 06:57:20

问题


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>

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.

The issues is i have a App Service managed cert setup for www.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)

So I thought I could fix it with the redirect to always go to www. but it does not seem to work


回答1:


UPDATE

You can RewriterConfig to set url rewrite function in web.config file. More details you can see my answer in anothor post .

PRIVIOUS

The Web Server integrated by App Service cannot have full control, which is one of the attributes of PaaS products.

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.

solution:

• Try to add redirect rule in the web config file. If it fails, you can only use the rewrite feature of the application gateway.

• The following are some documents of Application Gateway about rewrite feature for your reference.

Redirection

Redirect web traffic

Troubleshoot--App service issues



来源:https://stackoverflow.com/questions/61372611/azure-web-app-angular-not-redirecting-to-www

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!