IIS Rewrite sub domains to sub directories

Discussion in 'Site Programming, Development and Design' started by Gregory Bell, Mar 16, 2014.

  1. Hello,
    I need help. Below is my rewrite rules, but they are not working (or working incorrectly).
    I would like:
    xyz.com ==> www.xyz.com/moodle
    www.xyz.com ==> www.xyz.com/moodle
    cfdep.xyz.com ==> www.xyz.com/dnn
    sis.xyz.com ==> www.xyz.com/opensis
    uos.xyz.com ==> www.xyz.com/uoc
    str.xyz.com ==> www.xyz.com/str
    trq.xyz.com ==> www.xyz.com/trq

    the only thing that is working is the xxx.xyz.com. Everything is wrong.

    xyz.com shows the url in the browser as www.xyz.com/moodle
    all other urls (cfdep.xyz.com, etc) gives an error.

    Please help,
    Greg

    Code:
                   <rule name="Rewrite 1" stopProcessing="true">
                      <match url="(.*)" />
                         <conditions>
                            <add input="{HTTP_HOST}" pattern="^(www.)?xyz.com$" />
                            <add input="{PATH_INFO}" pattern="^/moodle($|/)" negate="true" />
                         </conditions>
                            <action type="Rewrite" url="moodle/{R:1}" />
                   </rule>
                   <rule name="Rewrite 2" stopProcessing="true">
                      <match url="(.*)" />
                         <conditions>
                            <add input="{HTTP_HOST}" pattern="^(cfdep.)?xyz.com$" />
                            <add input="{PATH_INFO}" pattern="^/dnn($|/)" negate="true" />
                         </conditions>
                           <action type="Rewrite" url="dnn/{R:1}" />
                   </rule>
                   <rule name="Rewrite 3" stopProcessing="true">
                      <match url="(.*)" />
                         <conditions>
                            <add input="{HTTP_HOST}" pattern="^(sis.)?xyz.com$" />
                            <add input="{PATH_INFO}" pattern="^/opensis($|/)"  negate="true" />   
                         </conditions>
                           <action type="Rewrite" url="opensis/{R:1}" />
                   </rule>
                   <rule name="CName to URL - Rewrite" stopProcessing="true">   
                      <match url=".*" />   
                         <conditions>
                            <add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.xyz\.com$" />
                         </conditions>   
                           <action type="Rewrite" url="/{C:1}/{R:0}" />
                   </rule>
    
     

Share This Page