Answer the question
In order to leave comments, you need to log in
How to write a generic redirect rule from www.subdomain.site.com to subdomain.site.com using IIS Url Rewrite?
There is a site in IIS, to which many (about 60) subdomains are attached:
sub1.site.com, sub2.site.com, ..., cubN.site.com
In the site code, the subdomain name determines which page to show ( regional versions of one site).
It is necessary to set up redirects when accessing addresses starting with www. For example, from www.sub1.site.com you need to redirect to sub1.site.com and so on for all subdomains.
currently this is implemented by the rule heap for URL Rewrite, like this:
<rule name="sub1" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.sub1.site.com$" />
</conditions>
<action type="Redirect" url="http://sub1.site.com/{R:0}" />
</rule>
Answer the question
In order to leave comments, you need to log in
Redirect from www to non-www
<rewrite>
<rules>
<rule name="Canonical" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www[.](.+)" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<rewrite>
<rules>
<rule name="Canonical" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^([a-z]+[.]com)$" />
</conditions>
<action type="Redirect" url="http://www.{C:0}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
, com - replace with your zone
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question