How to redirect https://domainname.com to https://www.domainname.com in Application Gateway

357 Views Asked by At

I have a secured website (using https certificate and WAF) balanced by the Azure application gateway. The problem is that when browsing the website without www then I got the error message that this site is not secured while if I add www.domainname.com I get the secured website. I tried in the application gateway a feature called Host Type Multiple/Wildcard as in the following screenshot Multiple/Wildcard

But that did not work. So the question is: How to redirect https://domaionname.com to https://www.domainname.com

1

There are 1 best solutions below

3
Rukmini On

I tried to reproduce the same in my environment and got the results successfully like below:

Once you create Application gateway and point it’s IP address to your custom domain name such as to redirect https://domaionname.com to https://www.domainname.com you can add another listener with hostname “www.example.com” and make sure that the previous listener with hostname “example.com” redirects to the newly added listener.

Try to add another listener HTTPS like below:

enter image description here

So, 2 HTTPs listeners with hostnames - one without www and one with www. Add a rule to redirect without www HTTPS listener to with www HTTPS listener.

And another rule to make sure that with www HTTPS listener is bound to a backend pool to serve the traffic like below:

Application gateway rule to redirect the listener 1 to listener 2.

enter image description here

enter image description here

I created a new rule for listener 2 to use the HTTPS settings to send traffic to my backend pool.

enter image description here

Now Application gateway for domain name redirect to https://www.domainname.com successfully like below:

enter image description here