IIS URL Rewrite help needed


I want to setup an IIS URL Rewrite that would do the following.

If the hostname in the url matches either:


Redirect the URL to


Essentially stripping out the "www" in these specific cases.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are these sites hosted on the same web server using the same single IP?
a rewrite under those circumstances is a resource consumer that is unneeded.
Presumably you are using host headers add the respective header to the correct site and IIs will display the correct content when the user hits www.sub1.domain.com.
If you do not want people to use www in the hostname of the subdomain, do not publish the www.sub1.domain.com record in DNS (note that some browsers when a user types in to the address bar sub1.domain.com will auto prepend the www when the http:// is not present. Those users will experience errrors)

Which IIS version (OS version where this is running)
the common
pattern match in the redirection directive
www\.(sub[0-9]+)\.domain.com/(.*)$ http://$1.domain.com/$2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skbohlerAuthor Commented:
Yes, I did write the article but I'm not good with the pattern recognition syntax.

We do use host headers (IIS 7)
We want to allow users to use "www".

The problem is that we use URL rewrite to switch from http to https for the domain. If we don't redirect www.sub1.domain to sub1.domain, then we have to purchase another subdomain for our SSL certificate, bind it, etc.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

skbohlerAuthor Commented:

Sorry for my ignorance, but what would I put in the Redirect URL properties if the condition is met?

not sure what article you mean,
the pattern match
http://www\/(sub[0-9]+)\.domain\.com/(.*)$ https://$1.domain.com/$2
will do what you want.

I am uncertain whether your version can handle the redirect config in web.config.
do all www.sub*.domain.com end up on the same

IMHO, you can still achieve the same thing given you already have redirect to secure site.
the rule presumably does not care which URL you are requesting via http:// any request will be redirected to https://subx.domain.com
So it will not pose a certificate error issue.

There is no avoiding the certificate issue when a user enters https://www.sub1.domain.com sine the error will show long before IIS sees the actual HTTP request.  Exchange of certificates to establish the secure connection happens first and the error will be displayed to the user before to approve in order for the secure connection to be established.
skbohlerAuthor Commented:
I'm doing it all through the IIS interface.

The redirect http://{C:1}.domain.com/{R:0} seems to work. Thanks!
Try the pattern I posted on a subset test site.

The following link covers the GUI approach after you follow the link, "Creating rewrite rules for the URL Rewrite Module.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.