In this post, I’ll show you how to redirect HTTP traffic to HTTPS on IIS 10 Server with WordPress blog.
This week I moved NTWEEKLY to Windows Server 2016 with IIS 10 and enabled SSL on all pages.
However, I didn’t force HTTPS on any of the pages and If you wanted to access the site using HTTP it was possible.
Today one of our users pointed out that we don’t force it and maybe we should.
So, I decided to take on the feedback and enabled it on the blog as you will see below.
Requirements
To get this working, I’m using the amazing URL Rewrite extension for IIS which can be downloaded from the link below.
https://www.iis.net/downloads/microsoft/url-rewrite
Configuration
The configuration part is not completed and will take around 2 minutes.
In my case, I’ll select the IIS website I need to configure redirection and double-click on the URL Rewrite icon
From the top right menu, I’ll Add Rule
Click on Black rule
I’ll name the rule HTTPs and Select Wildcards with * Pattern and tick the Ignore case tick box
In the condition input, I’ll type:
{HTTPS}
And Matches the Patten
Pattern: off and ignore case
In the action menu, I’ll use the code below and tick append query string with 302 redirection type.
https://{HTTP_HOST}{REQUEST_URI}
If you are using IIS there is no need to restart anything and the rule will work immediately.
WEB Config
Once the change is done, the Web.Config file will be updated with the configuration below
</rule> <rule name="HTTPS" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" /> </rule>