« Previous Next »

Thread: Where to start..possible?

Last post 06-13-2008 4:20 PM by Kanien. 5 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (6 items)

Sort Posts:

  • 06-11-2008, 5:17 PM

    • Kanien
    • Top 75 Contributor
    • Joined on 01-30-2008, 7:14 PM
    • Posts 104

    Where to start..possible?

    First off, wow.  Nice to see IIS7 having its own built in mod-rewrite.  I've been working with *nix/apache for years and this is one of the last pieces of the puzzle that I wanted to duplicated on windows/iis.

     I'm interested in being able to put multiple domains on one IIS 'site' and having each domain (host header) rewrite to a separate webroot.  I'd love some suggestions if this is possible and if so some examples how.

    Example: Website with headers for the separate domains: www.contoso.com/contoso.com & www.contoso2.com/contoso2.com

    www.contoso.com -> \inetpub\wwwroot\com\contoso\www\

    www.contoso2.com -> \inetpub\wwwroot\com\contoso2\www\
     

     

  • 06-11-2008, 8:02 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 651

    Re: Where to start..possible?

    To better understand how to implement sub-domains with URL rewriter I would recommend to start with this walkthrough: http://learn.iis.net/page.aspx/468/using-global-and-distributed-rewrite-rules/

    http://ruslany.net
  • 06-12-2008, 4:28 PM In reply to

    • Kanien
    • Top 75 Contributor
    • Joined on 01-30-2008, 7:14 PM
    • Posts 104

    Re: Where to start..possible?

    Not sub domains, separate domains.  Domain1 and Domain2 and then rewriting it to a new wwwroot.

     Been running into issues with my reg ex ;/

     # <Directory ~ "D:/Inetpub/virtual/[a-zA-Z0-9]+/">
     #   RewriteEngine On
    #
    #    RewriteCond %{HTTP:Host} ^(www\.)?(.+) [NC]
    #    RewriteCond D:/Inetpub/virtual/%{APP_POOL_ID}/%2/wwwroot -d [NC]
     #   RewriteRule (.*) /%2/wwwroot$1 [L]
    #
     #   RewriteRule (.*) /wwwroot$1 [L]
    # </Directory>

  • 06-12-2008, 5:18 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 7:38 PM
    • Redmond, WA
    • Posts 651

    Re: Where to start..possible?

    I see. Here is a possible rule for that:

    <rule name="domains" stopProcessing="true">
         <match url="(.*)" />
              <conditions>
                  <add input="{HTTP_HOST}" pattern="^(www\.)?(.+)" />
                  <add input="C:\inetpub\virtual\{C:2}\wwwroot" matchType="IsDirectory" />
              </conditions>
          <action type="Rewrite" url="{C:2}/wwwroot/{R:1}" />
    </rule>

    I am not clear on why do you need to use the {APP_POOL_ID} server variable.

    http://ruslany.net
  • 06-13-2008, 4:15 PM In reply to

    • Kanien
    • Top 75 Contributor
    • Joined on 01-30-2008, 7:14 PM
    • Posts 104

    Re: Where to start..possible?

    First off, Russlany, thanks for your time.  After playing with the mod for a few hours I was able to reproduce what I wanted to an extent.  Let me try to explain my enviornment.

     Webroot = d:\inetpub\virtual\wwwroot\username (the username is the same as the {APP_POOL_ID})  Inside the webroot, the structure looks like this d:\inetpub\wwwroot\username\domain.com\www\info.php.  The rewrite goes to that exact doc root and the domain.com and the www are based upon the capture, thus http://sub.domain.com would rewrite to d:\inetpub\wwwroot\username\domain.com\sub\. 

     The re-write is now not my problem. I am able to successfully re-write to the directory I want, but I have a relative path issue now.  I'll attach a SS.  This is a test domain thats path is d:\inetpub\wwwroot\maxima2a\wwwroot\info.php.  If you look closely you see that the php logo is missing from the top right, I pulled up the properties to view the address.

     relative path

  • 06-13-2008, 4:20 PM In reply to

    • Kanien
    • Top 75 Contributor
    • Joined on 01-30-2008, 7:14 PM
    • Posts 104

    Re: Where to start..possible?

    These are my rules.  I fixed the image above, sorry about the error link.

           <rewrite>
                <rules>
                    <clear />
                    <rule name="Sub" stopProcessing="true">
                        <match url="(.*)" ignoreCase="false" />
                        <conditions>
                            <add input="{HTTP_Host}" pattern="^([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-]+\.[a-zA-Z]+)$" />
                            <add input="d:\inetpub\virtual\{APP_POOL_ID}\{C:2}\{C:1}" matchType="IsDirectory" />
                        </conditions>
                        <action type="Rewrite" url="/{C:2}/{C:1}/{R:1}" />
                    </rule>
                    <rule name="Default Domain" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^([a-zA-Z0-9\-]+\.[a-zA-Z]+)$" />
                            <add input="d:\inetpub\virtual\{APP_POOL_ID}\{C:1}\www" matchType="IsDirectory" />
                        </conditions>
                        <action type="Rewrite" url="{C:1}/www/{R:1}" />
                    </rule>
                    <rule name="Default" stopProcessing="true">
                        <match url="(.*)" ignoreCase="false" />
                        <action type="Rewrite" url="/wwwroot/{R:1}" />
                    </rule>
                </rules>
            </rewrite>

Page 1 of 1 (6 items)
Microsoft Communities