Search code examples
iishttpsurl-rewritinghttp-redirect

Redirect http to https via IIS


I have this application that I just installed a SSL certificate for. Yest I tried to redirect the users to use only the HTTPS://url.com. and prevent them from using the http://url.com site. However because I lack understanding the regular expressions to define the Pattern and the condition and unfortunately, I could not find a guide with some example of how to define those rules. I would like a concrete example of how to set this up https://{HTTP_HOST}{REQUEST_URI}.


Solution

  • Ensure you have the URL Rewrite feature added. In IIS manager configure the following in the URL rewrite section.

    1. Create inbound rule (Blank Rule)
    2. Requested URL : Matches the pattern
    3. Using: Wildcards
    4. Pattern: *

    Conditions

    • Input: {HTTPS}
    • Type: Matches the pattern
    • Pattern: off

    Action

    • Action Type: Redirect
    • Redirect URL: https://{HTTP_HOST}{REQUEST_URI}
    • Append Query String Checked
    • Redirect type: Found (302)

    Once you have done this. Create a condition.

    1. Right click your new rule
    2. Conditions -> Add+
    3. Condition Input : {QUERY_STRING}
    4. Matches the Pattern
    5. Pattern: off

    Essentially it should look like this:

    Redirect Rule

    All traffic using a http request will be automatically redirected to the https port.