Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a webapp that is located in /subdir1/subdir2/ I'd like to simplify it for the users by adding a subdomain but it keeps looping. I'd tried to add additional rules to prevent it but no joy.

So what happens is

My rule in web.config:

<rule name="subdomain" stopProcessing="true">
                <match url="^(?!sub/)(.*)" />
                    <add input="{HTTP_HOST}" pattern="" negate="true" />
                    <add input="{HTTP_HOST}" pattern="" />
                <action type="Rewrite" url="subdir1/subdir2/" appendQueryString="true" />

Any ideas?

Edit: So what i'm really trying to do is make it easier for the users. Right now they have to type to access the login page for the product. What I wanted to do was create a single subdomain that would rewrite to the above link. Rather than typing the long url just go to and it would redirect or rewrite to the location. I hope that makes my desire a bit more clear.


share|improve this question

{HTTP_HOST} represents only the host part of a URI:


Thus, your first condition is irrelevant (it will never evaluate false).

What you want is {PATH_INFO}:

<add input="{PATH_INFO}" pattern="^/subdir1/subdir2" negate="true" />

Effectively saying: "If this part of the URL:[PATH_INFO] starts with "/subdir1/subdir2", don't rewrite

If you want /additional/path/to/content.html rewritten to /subdir1/subdir2/additional/path/to/content.html, you'll need a back-reference to the match as well:

<action type="Rewrite" url="subdir1/subdir2/{R:0}" appendQueryString="true" />
share|improve this answer
Sounds correct but didn't fix it. Tried playing with the pattern too. Leading / ending / ^ no ^, still the same behavior. – Ross R Sep 17 '13 at 21:33
It's a bit difficult to help without knowing what you expect and what actually happens, but I've updated my answer on intuition – Mathias R. Jessen Sep 18 '13 at 0:27
Updated my post to hopefully be a bit clearer. Thanks for the help. – Ross R Sep 18 '13 at 13:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.