IIS URL Rewriting - With Multiple Domains

I have a website / application where the same pages launch many websites (depending on the URL the pages display different logos / css / content, etc.). I am trying to get every website domain to be redirected to www. domain verification.

I used the standard canonical rule to start in the Rewrite URL, and then changed the URL match pattern from:

(.*) 

To:

 (^domain*) 

So this will only do this for non-www. versions of the current domain and do not match for all domains.

My plan is to create one for each domain that uses the system to redirect each of them to www. version.

When I test the template in IIS, this rule matches (I think) what it should do. But when I go to the site, it is not redirected, it just remains on non-www. version.

Does anyone know where I am wrong or is this possible?

Thanks J.

UPDATE Thought I'd try to give a better explanation:

I have one site setup in IIS. The pages of this website have many websites of the same type, the style, logo and products on each website vary depending on the URL.

Let's say I have the following binding settings on a website:

www.domain1.com, domain1.com, www.domain2.com, domain2.com, www.domain3.com, domain3.com

The website will display a different website with different content, styles, etc. depending on the url.

If I then use the default "Canonical domain name" rule in the Rewrite URL, you need to select one domain for forwarding, so if I select www.domain1.com, it will add the 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> 

Then it forwards everything to www.domain1.com. Therefore, if a user visits domain2.com or www.domain2.com, they will be redirected to www.domain1.com.

I need people to be redirected like this:

domain1.com> www.domain1.com

domain2.com> www.domain2.com

domain3.com> www.domain3.com

When testing new websites to add to existing ones, we install them in a subdomain, so I also require that the subdomains continue to not be redirected.

But the problem is to do this in the same website file / web.config.

+8
redirect url-rewriting iis iis-8
source share
1 answer

Try the following (@Atashbahar credit on https://stackoverflow.com/a/318353/... ):

 <rewrite> <rules> <rule name="Add WWW" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" /> </conditions> <action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" /> </rule> </rules> </rewrite> 
+3
source share

All Articles