0

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 '.'?

Daniel Plomp
  • 174
  • 1
  • 12
  • i think you might want to add the 'regex' tag to your question. the pattern is regex i believe and someone who can rewrite your regex in the sections above may help you find an answer. – Taylor Brown Jan 14 '15 at 16:38

1 Answers1

0

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>
Community
  • 1
  • 1
TGlatzer
  • 5,815
  • 2
  • 25
  • 46