Reputation: 2983
We have a site set up on an azure app service. We have an application gateway setup to act as a waf, however it seems to be causing issues with our non www to www redirect which is shown below. The redirect works as expected when browsing directly to the site which points to the waf being the problem. Has anyone experienced this issue. I suspect the host is changed to xxxxx.azurewebsites.net when it forwards the request on but can find no documentation about this. Has anyone experienced this before?
<rule name="Prepend WWW" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(.*)azurewebsites.net$" negate="true" />
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
</conditions>
<action type="Redirect" url="https://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
Upvotes: 0
Views: 1564
Reputation: 28274
There is a simple way to directly redirect a none-www
hostname in the URL to www
hostname on the DNS level without having conditions rules on web.config
. You could create a CNAME
record that maps non-www
domain example.com
to www.example.com
in your domain DNS provider. Your domain DNS provider may need support CNAME records in the root domain. You also could map www.example.com
to your application gateway IP address.
Another way is to configure redirection and routing rules on the application gateway level. You may add two multi-site listeners, one is for host example.com
, another is for host www.example.com
. Then configure the redirection from one listener to another listener. You could get more info on the Application Gateway redirect overview.
Upvotes: 0