question

SudeshSharma-4223 avatar image
0 Votes"
SudeshSharma-4223 asked MotoX80 edited

redirect http to https all pages of website

Hey Guys

I have created and hosted a react node web app on azure VM. I have purchased a wildcard SSL Certificate from azure. I have defined below web.config file for URL redirection.


<?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" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>

             <rule name="httptohttps" stopProcessing="true">
                 <match url="(.*)" />
                 <conditions>
                     <add input="{HTTPS}" pattern="^OFF$" />
                 </conditions>
                 <action type="Redirect" url="https://%{HTTP_HOST}%{REQUEST_URI}" />
             </rule>
             <rule name="non-wwwtowww" stopProcessing="true">
                 <match url="(.*)" />
                 <conditions>
                     <add input="{HTTP_HOST}" pattern="^abc\.com$" />
                 </conditions>
                 <action type="Redirect" url="https://www.abc.com/{R:1}" />
             </rule>
         </rules>  
     </rewrite>
 </system.webServer>  

</configuration>


Above URL redirection works for only the main page abc.com not for all other pages of the website.

For example, If the user enters http://abc.com/home then the page redirects to https://www.abc.com/home

How it's possible in web.config file

azure-virtual-machines
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am currently investigating and will get back to you shortly. Thanks.

0 Votes 0 ·
karishmatiwari-msft avatar image
1 Vote"
karishmatiwari-msft answered

Can you please check the following posts which might help resolve this issue :

  1. https://stackoverflow.com/questions/39914184/wildcard-subdomains-on-azure

  2. This explains some ways to create the rule in portal itself by adding a new routing rule rather than the app level

https://docs.microsoft.com/en-us/azure/frontdoor/front-door-how-to-redirect-https

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
1 Vote"
MotoX80 answered MotoX80 edited

Does your web site use relative links for all images/stylesheets/links/etc?

What I used to do was to define 2 web sites. The main site only had the HTTPS binding. The second "redirect site" only had the HTTP binding.

On the "redirect site", configure it to send everything to the HTTPS site. That should avoid having to add a bunch of rewrite rules.

Set the home directory for the redirect site to an empty folder. Or maybe just put a default page there that says that something went wrong.


137038-capture.jpg




capture.jpg (36.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.