Converting IIS7 URLRewrite Rules

Topics: User Forum
Sep 19, 2011 at 2:37 PM
Edited Sep 19, 2011 at 2:39 PM

Hi,

I have successfully installed and appear to running the rewrite filter fine. However I am getting myself into a mess trying to convert some IIS7 rules. Below are the current IIS7 rules I have running;

           <rules>

               <rule name="Site5">

                   <match url=".*" />

                   <conditions>

                       <add input="{HTTP_HOST}" pattern="^(www.)?192.168.1.24$" />

                       <add input="{PATH_INFO}" pattern="^/Sites/5/" negate="true" />

                   </conditions>

                   <action type="Rewrite" url="\Sites\5\{R:0}" />

               </rule>

               <rule name="Site2">

                   <match url=".*" />

                   <conditions>

                       <add input="{HTTP_HOST}" pattern="^(www.)?localhost$" />

                       <add input="{PATH_INFO}" pattern="^/Sites/2/" negate="true" />

                  </conditions>

                   <action type="Rewrite" url="\Sites\2\{R:0}" />

               </rule>

           </rules>

The site I am constructing has multiple domains that run separate home pages for different customers but all run off the same code. Eventually domains will be redirected to e.g.;

Root\Sites\5\default.aspx

For now I am just using my internal and loopback IP addresses to test. The structure of my site is as follows;

Root\Iirf.ini

Root\Resources

Root\Functions

Root\Sites\5

Root\Sites\5\Resources

Root\Sites\5\Functions

Each of the “sites” (i.e. 5 or 2) folders has virtual directory links back to the folders further up the tree. This is needed so when the urlrewrite happens resources can still be found. I have tried many different rules and at the moment am trying the following:

--------------------------------------------------------------------------

RewriteCond %{HTTP_HOST}           ^(www.))?192.168.1.24$

RewriteCond %{PATH_INFO}           !^/Sites/5/$

RedirectRule ^.*       \Sites\5\$1 [L]

-------------------------------------------------------------------------

This appears to put the browser in a loop I am guessing because as it rewrites to \Sites\5\$1 it then matches the same rule again. Any help would be much appreciated. Hopefully I am fairly close.

Regards,

Shaun

Coordinator
Sep 20, 2011 at 12:32 AM

It looks to me like your slashes are going the wrong way.  The target of the rewrite is a URL path.  It is not a path in the IIS metabase. It is not a filesystem path.  The slashes should lean this way /  like in any URL.

The rule you have, redirects to the path.  The condition you use deals with PATH_INFO.  It compares PATH_INFO, to /Sites/5/   The ^ and $ refer to beginning-of-string and end-of-string respectively.  Therefore any URL that is not exactly /Sites/5/   will be rewritten.  A url such as /Sites/5/X will be redirected.  And it will be redirected endlessly.   

You'll need to change your condition, or change your redirect rule, or a combination of those things.