Reputation: 13243
I followed these instructions http://www.dotnetexpertguide.com/2011/08/iis-7-redirect-domaincom-to.html
After some tweeking I can get it to work somewhat, but not completely how I would like. Here are my settings:
These settings work when i goto 'domain.com' by itself, it will redirect to 'www.domain.com'
However, When I goto an inner page on the domain, like 'domain.com/aboutus.html', it does not redirect to 'www.domain.com/aboutus.html', which is how I would like it to work.
I cannot use (.*)
for a pattern, because there is a wildcard on the domain, which means if i type in anythingiwantto.domain.com it will redirect me to 'www.', which is not how I want it.
What I am looking for is the setting to not only redirect to 'www.domain.com' when it is ONLY 'domain.com' (no subdomains), but also to redirect any inner page in the same fashion.
FOR EXAMPLE:
anything.domain.com = does nothing
anything.domain.com/anything.html = does nothing
domain.com = redirect to www.domain.com
domain.com/anything.html = redirect to www.domain.com/anything.html
Also, I cannot use conditions to allow those subdomains individually, because there are too many subdomains to allow. I was thinking of adding a separate rule for inner pages, but I don't know how to write the expression for this.
Upvotes: 2
Views: 6723
Reputation: 115
Same thing can be done to remove the prefix also. A blog post for the same at following URL:
http://karmic-development.blogspot.in/2013/10/add-prefix-www-automatically-in-url-in.html
Upvotes: 0
Reputation: 9918
<rule name="Add WWW prefix to DOMAIN.COM">
<match url="(.*)" ignoreCase="true"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com"/>
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent"/>
</rule>
Upvotes: 6