简体   繁体   中英

Using IIS Url Rewrite from HTTPS to another HTTPS

I am trying to redirect my site from https://localhost (but written with the ip, like https://10.0.7.8 ) to another https location like https://mysite.com

My current configuration is:

<rewrite>
  <rules>
    <rule name="Rewrite to mysite.com" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <action type="Redirect" url="https://mysite.com/{R:0}" redirectType="Permanent" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="https://10.0.7.8*" />
      </conditions>
     </rule>
  </rules>
</rewrite>

And when I am accessing https://10.0.7.8 it does not go to https://mysite.com , it stays on https://10.0.7.8

Any idea what am I doing wrong?

You need to split the https part from the ip in 2 conditions:

<rewrite>
  <rules>
    <rule name="Rewrite to mysite.com" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^10\.0\.7\.8$" />
        <add input="{HTTPS}" pattern="^ON$" />
      </conditions>
      <action type="Redirect" url="https://mysite.com/{R:0}" redirectType="Permanent" />
     </rule>
  </rules>
</rewrite>

Also, 10.0.7.8 needs to be written 10\\.0\\.7\\.8 because the . needs to be escaped as it is a special character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM