How do I use IIS ReWrite redirect from server name to fully qualified domain name

364 Views Asked by At

I have an internal domain iis server which has a website that is bound to https

sitename and sitename.domain.com

but it also accepts http to

sitename and sitename.domain.com

I want to redirect using iis url rewrite so when someone enters http://sitename/?foo=bar it redirects to https://sitename.domain.com/?foo=bar

I also want to redirect url https://sitename/?foo=bar to https://sitename.domain.com/?foo=bar

I have not been able to get this working at all

1

There are 1 best solutions below

0
samwu On BEST ANSWER

You can try this rule:

<rule name="test" stopProcessing="true">
  <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^sitename$" />
      <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
  <action type="Redirect" url="https://sitename.domain.com/{R:1}" />
</rule>