简体   繁体   中英

IIS rewrite rules to enforce HTTPS and one of several canoncial domains

The site I'm looking after has multiple canoncial domains - eg

example.com
example.com.au
example.co.nz

as well as some 'other' domains that need to be redirected to one of the canoncial domains (eg example.us should go to example.com ).

All sites should be accessed via HTTPS

Is it possible to write a concise rule for each canoncial domain that redirects the user to that domain iff

  • They're not on the canoncial domain (eg www.example.com , example.us ) OR
  • The connection is not HTTPS

I think I can see how to do it wih multiple rules, but it will quickly become fiddly (so concise rules would be nicer)

I achieved it with the following (shoved multiple variables into the input with a # delimter):

<rule name="Redirect to example.co.nz" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions  logicalGrouping="MatchAll">
    <add input="{HTTPS}#{HTTP_HOST}" pattern="(^OFF)|(^.*#www\.)" />
    <add input="{HTTP_HOST}" pattern="^(www\.)?example.co.nz$" />
  </conditions>
  <action type="Redirect" url="https://example.co.nz/{R:1}" />
</rule>

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