Redirect to HTTPS just one domain of many.

RAN55 181 Reputation points
2021-09-28T06:30:00.787+00:00

Hello,

I have IIS site with many bindings, i need redirect to HTTPS just one of them.

All info i found is about redirect all trafic with URLRewrite, but i need redirect only one domain.

How can I do it?

Thanks,

Windows development | Internet Information Services
0 comments No comments

Answer accepted by question author
Sam Wu-MSFT 7,571 Reputation points Microsoft External Staff
2021-09-29T03:00:40.013+00:00

Hi @Pedro-A

You can try to set pattern(the rule pattern is used to specify either the regular expression or a wildcard pattern that is used to match URL strings.) to match only one domain, usually when redirecting from http to https, we always use (.*) to match the URL string, (.*) means to match any string, you can set the parameter to match only one domain.

You can refer to this rule:

<rule name="Redirect to HTTPS" stopProcessing="true">  
  <match url="^one domain$" />     
    <conditions>  
      <add input="{HTTPS}" pattern="^OFF$" />  
    </conditions>  
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />  
</rule>  

If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. RAN55 181 Reputation points
    2021-10-01T10:47:12.44+00:00

    Hi,

    I had to add two conditions:

         <match url="(.*)" />
         <conditions>
           <add input="{HTTP_HOST}" pattern="^www.domain.com$"/>
           <add input="{HTTPS}" pattern="^OFF$" />
         </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
    

    Now, the others bindings/domains still respond HTTP and one domain redirect to https.

    Thanks for help SamWu ;)

    Regards,

    Was this answer helpful?


  2. RAN55 181 Reputation points
    2021-09-29T10:02:38.733+00:00

    Ok, i understand.

    This is the rule and still not working.

    136311-imagen.png

    If i set "R1" it says ·the rule back reference "1" is not valid.

    I also try to use in redirect "https://www.domain.com"

    Was this answer helpful?


  3. RAN55 181 Reputation points
    2021-09-29T06:40:47.367+00:00

    This is the rule:

    rule name="HTTPS Redirect" stopProcessing="true">
                        <match url="^www.domain.com$" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{REQUEST_URI}" />
                    </rule>
    

    But doesnt work.

    If i browse the http port 80 binding in the server, it redirect to https, but not from another computer.

    Must i delete the http port 80 binding ?

    If i use https://{HTTP_HOST}/{R:1} instead https://{HTTP_HOST}/{REQUEST_URI} still not working.

    Im using W2012

    Thanks,

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.