# IIS 7.5 URL Rewrite looping

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

My rule in web.config:

<rule name="subdomain" stopProcessing="true">
<match url="^(?!sub/)(.*)" />
<conditions>
</conditions>
<action type="Rewrite" url="subdir1/subdir2/" appendQueryString="true" />
</rule>


Any ideas?

Edit: So what i'm really trying to do is make it easier for the users. Right now they have to type www.domain.com/subdir1/subdir2/ 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 sub.domain.com and it would redirect or rewrite to the www.domain.com/subdir1/subdir2/ location. I hope that makes my desire a bit more clear.

Thanks!

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

http://[HTTP_HOST]/subdir/index.html.

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: http://sub.domain.com[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" />

• 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