问题描述:

I'd like to add www to every domain name of a website.

These are the domains I like to include:

  • domain.com
  • domain.nl
  • domain.de
  • domain.co.in

What I have so far is:

<rule name="Prepend www to 2nd level domain names" enabled="true" stopProcessing="true">

<match url=".*" />

<conditions trackAllCaptures="true">

<add input="{HTTP_HOST}" pattern="^([^.]+\.[^.]+)$" />

<add input="{CACHE_URL}" pattern="^(.+)://" />

</conditions>

<action type="Redirect" url="{C:2}://www.{C:1}/{R:0}" />

</rule>

This works for all the domains, except the co.in. I'm not sure how I can also include TLD's with more than one '.'?

网友答案:

you could use <add input="{HTTP_HOST}" pattern="^domain.*" />

A longer Version how it works is here: Forwarding http://mydomain.com/ctrlr/act/val to http://WWW.mydomain.com/ctrlr/act/val

Which essentially is the same as i wrote above.
Here is the rule adapted to support TLD

<rule name="Add WWW prefix" >
  <match url="(.*)" ignoreCase="true" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^domain\.(.*)" />
  </conditions>
  <action type="Redirect" url="http://www.domain.{C:1}/{R:1}"
          redirectType="Permanent" />
</rule>
相关阅读:
Top