I'd like to use the URL Rewrite module in IIS 7.5 to redirect all requests not from a particular sub-domain (x.domain.com) to a specific folder/file.
For example, these should work as-is:
x.domain.com
x.domain.com/asdf
While anything like these:
y.domain.com
y.domain.com/asdf
domain.com
domain.com/asdf
Should redirect to a specific page like this (exact URL, not dependent upon sub-domain used):
domain.com/a
Unfortunately I can't get the rule configured correctly, as while it matches correctly, most of the time, when it does it just results in a redirect loop. (I know I should put the faulty rules I have setup now, but they're not even consistently resulting in a redirect loop.)
Setting up another Web site in IIS that matches www.domain.com and domain.com is the easy solution, but I'd much rather have one Web site that handles it all and redirects.
What's the correct setup to get this behavior (either using the UI or adding it to the Web.config directly).
Thanks!
Since you haven't posted your existing rule (the one that results in redirect looping), I can't tell you why it doesn't work. I can tell you what should work though:
Here we have to rules, one to rewrite all requests where the url matches
domain.com
except for host headers exactly matchingx.domain.com
anddomain.com
(to avoid looping).The second rule matches requests for exactly
domain.com
and to any other place than/a/
and redirects them if necessaryMathias' answer got me what I needed. The exact rules I had to drop in place are below, and involved just two changes:
Match URL is actually based upon the path, so I had to change that to match anything (or nothing), which is fine since IIS has bindings setup correctly on the site and the conditions will capture it correctly.
The enum for logicalGrouping needs to be MatchAll.