Reputation: 12703
I currently have this CanonicalHostNameRule.
We have multiple top-level domains (.ch and .de), that is why we don't use the default CanonicalHostNameRule from IIS.
<rule name="RedirectToWWW" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(\S+)\.(de?|ch)$" />
</conditions>
<action type="Redirect" url="https://www.{C:0}/{R:0}" />
</rule>
This works for
But not for
http://holdrio.supertext.ch
http://ww.w.supertext.ch
http://www.mail.supertext.ch
and I really would like something that redirects any subdomain to www.supertext.ch or .de respectively. Any ideas?
Upvotes: 0
Views: 155
Reputation: 161
You could use following pattern: ^(?!www\.supertext\.[de|ch])(\S+)\.(de|ch)$
The results would be for example:
holdrio.supertext.ch ->
holdrio.supertext.de->
supertext.ch->
<rule name="RedirectToWWW" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.supertext\.[de|ch])(\S+)\.(de|ch)$" />
</conditions>
<action type="Redirect" url="https://www.supertext.{C:2}/{R:0}" appendQueryString="true" redirectType="Permanent"/>
</rule>
Note: www.supertext.ch.supertext.ch is not covered
I hope this works for you.
Upvotes: 1