I have a website/application where the same pages run many websites (depending on the URL the pages display different logo/css/content etc). I am trying to force each website domain to redirect to the www. verison of the domain.
I have used the default Canonical Rule to start with in URL Rewrite then just changed the Match URL Pattern from:
(.*)
To:
(^domain*)
So that it will only do this for the non-www. version of the current domain and not match for all domains.
My plan is to create one of these for each domain that uses the system to redirect each one to the www. version.
When I test the pattern in IIS the rule matches as (I think) it should do. But when I go to the website it doesn't redirect, it just stays on the non www. version.
Does anyone know where i'm going wrong or if this is even possible?
Thanks J.
UPDATE Thought i'd try and give a better explanation:
I have one website setup in IIS. The pages of this website run many websites of the same type, the style, logo and products on each website change depending on the URL.
So say I have the following bindings setup on the website:
www.domain1.com, domain1.com, www.domain2.com, domain2.com, www.domain3.com, domain3.com
The website will serve up a different looking website, with different content, styles etc depending on the URL.
If I then use the default 'Canonical domain name' rule in URL Rewrite you have to pick one domain to forward to, so if i chose www.domain1.com it adds rule:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain1\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domain1.com/{R:1}" />
</rule>
</rules>
</rewrite>
This then forwards everything to www.domain1.com. So if a user visits domain2.com or www.domain2.com they will get redirected to www.domain1.com.
I need it so that people get redirected as follows:
domain1.com > www.domain1.com
domain2.com > www.domain2.com
domain3.com > www.domain3.com
When testing new websites to add to the existing ones, we set them up on a sub domain, so I also require sub domains to continue to not be re-directed.
But the issue is with doing this within the same website/web.config file.