B
B
Bob Smith2015-05-19 13:20:40
IIS
Bob Smith, 2015-05-19 13:20:40

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>

Is it possible to set up similar behavior with a single rule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2015-05-20
@bob_smith

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>

Redirect from non-www to www
<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 question

Ask a Question

731 491 924 answers to any question