We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

wildcard host headerRSS

18 replies

Last post Oct 17, 2008 07:30 PM by brahmg

  • wildcard host header

    Jul 19, 2008 12:53 AM|jimrPA|LINK

    Can this be done? Wildcard host headers or is it just rewriting urls after the .tld/

     

    thanks

     

  • Re: wildcard host header

    Jul 19, 2008 02:15 AM|ruslany|LINK

    Host header can be used within rewrite rules. Can you give an example of what kind of rewriting you want to do?

    Wildcards

  • Re: wildcard host header

    Jul 19, 2008 09:38 AM|jimrPA|LINK

    all *.example.com maps to a single website

     http://forums.iis.net/t/1095760.aspx

     

    Thanks

  • Re: wildcard host header

    Jul 21, 2008 12:34 PM|DanielVL|LINK

    I think Ruslan will be out of office today, so I think what you need is something like:

       <rule name="Host example" patternSyntax="Wildcard">
        <match url="*" />
        <conditions>
         <add input="{HTTP_HOST}" pattern="*.example.com" />
        </conditions>
        <action type="Redirect" url="http://www.live.com" redirectType="Permanent" />
       </rule>

     Thanks.

     

    Wildcards Headers

    Daniel Vasquez Lopez
    IIS Team
  • Re: wildcard host header

    Jul 21, 2008 02:13 PM|jimrPA|LINK

    OK, I will give it a try. Thanks

  • Re: wildcard host header

    Jul 21, 2008 03:29 PM|jimrPA|LINK

    no, I couldn't get this to work. I can get it to map to /userfolder and it works fine, but having it change *.domain.com to domain.com, is just not working? Any other ideas?

  • Re: wildcard host header

    Jul 21, 2008 05:01 PM|ruslany|LINK

    Having read the other thread that you referenced, I think what you are trying to do is to configure several web sites like this:

    Website1 with host header binding as "*.example.com"
    Website2 with host header binding as "*.example.org"

    So that if request is for foo.example.com then it goes to Website1 and request for foo.example.org goes to Website2.

    If that's what you are trying to do, then one theoretically possible way to achieve that is to use URL rewrite module together with ARR module to proxy the requests based on the host header For example, create the following three web sites on the same server:

    • <div mce_keep="true">ProxySite with empty host header binding</div>
    • <div mce_keep="true">Website1 with host header binding as "example.com"</div>
    • <div mce_keep="true">Website2 with host header bidning as "example.org"</div>

    On the "ProxySite" create a rewrite rule to proxy requests to other two web sites:

    <rule name="Proxy by host">
      <match url="(.*)"/>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(?:[^.]*\.)?([^.]+\.[^.]+)$" />
      </conditions>
      <action type="Rewrite" url="http://{C:1}/{R:1}" />
    </rule>

    This way, if request is made to http://foo.example.com/default.aspx?bar=1 then the ProxySite with empty host header binding will get it and then the rewrite rule will proxy the request to http://example.com/default.aspx?bar=1, which means that Website1 will get the request.

    Note that for this to work you need to install ARR module.

    Rules Headers

  • Re: wildcard host header

    Jul 21, 2008 07:38 PM|jimrPA|LINK

    You nailed it perfect. Thanks :)

  • Re: wildcard host header

    Sep 09, 2008 10:34 PM|brahmg|LINK

     If it's ok I'd like to tag along and add my own question to this.. Basically I'm in the same boat, I tried to use your example and modify it for my case but I can't seem to get it to work as a Rewrite..while it does write out correctly as a Redirect . When I try it as a rewrite I receive a "Bad Request" message..

     I'm trying to setup dev environments, and the way that I have to set up the server is.

    module.username.server.dns.com so.. basically.. testmod.mikesmith.devbox.companyname.com, and I need it to rewrite to

    mikesmith.devbox.companyname.com/testmod

    I've set up a Proxy site with no bindings, and a site named mikesmith.devbox.companyname.com

     

    With the follow (and set to redirect) it works perfectly. Redirecting to  mikesmith.devbox.companyname.com/testmod

      <rule name="Proxy by host" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
     <add input="{HTTP_HOST}" pattern="^(.*)\.([^.]+\.devbox\.companyname\.com)$" />
      </conditions>
      <action type="Rewrite" url="http://{C:2}/{C:1}" appendQueryString="false" redirectType="Permanent" />
    </rule>

     Yet when I change it to rewrite (as seen above).. it flops. I am new to regular expressions, and rewrites so any help would be great.

     

    Wildcards Rewrite Map redirection

  • Re: wildcard host header

    Sep 10, 2008 01:35 AM|ruslany|LINK

    I think you may need to configure ARR to not preserve original host headers when forwarding requests. There is a configuration property in ARR schema called preserveHostHeader. Try setting it to False.

    proxypass

  • Re: wildcard host header

    Sep 10, 2008 12:33 PM|brahmg|LINK

    Thank you for your prompt reply. If you don't mind can you point me to/or give me a brief walk threw as to how to setup ARR for the above scenerio. I just installed it, but didn't configure anything and am unfamiliar with the module.

     Thanks again.

    -Brahm

  • Re: wildcard host header

    Sep 10, 2008 01:00 PM|ruslany|LINK

    1. <div mce_keep="true">Open IIS Manager and select server node in the tree view on left hand side</div>
    2. <div mce_keep="true">Double click on "Application Request Routing" icon</div>
    3. <div mce_keep="true">In the Actions pane on right hand side select "Server Proxy Settings"</div>
    4. <div mce_keep="true">In the dialog uncheck "Preserve Host Header"</div>

    reverse proxy proxypass

  • Re: wildcard host header

    Sep 10, 2008 01:58 PM|brahmg|LINK

    Thank you again, for your quick response. Unfortunately what this is doing is making re-write act like a redirect. .so url actually switches from var.ect.ect.com to ect.ect.com/var/ which cause me to loose the dir structure for dynamic linking.

    -Brahm

  • Re: wildcard host header

    Sep 10, 2008 02:27 PM|anilr|LINK

    You will also need to set reverseRewriteHostInResponseHeaders to true - I do not remember exactly what this option is called in the UI.

    Anil Ruia
    Software Design Engineer
    IIS Core Server
  • Re: wildcard host header

    Sep 10, 2008 05:14 PM|brahmg|LINK

    Hi, thank you for your reply.

     Even with said box checked it still replaces the url from var.ect.ect.com to ect.ect.com/var/

  • Re: wildcard host header

    Sep 10, 2008 05:23 PM|anilr|LINK

    Can you collect failed request tracing log on the server for the request you are making - just turn on rule for all status codes (200-999) - I expect that your app is generating links with absolute urls in the html, which will of course not work.

    btw, you can e-mail me the freb logs at anil (dot) ruia (at) microsoft (dot) com - make sure to include logs from the site doing the rewrite and the site the request is finally being served from.

    Anil Ruia
    Software Design Engineer
    IIS Core Server
  • Re: wildcard host header

    Sep 10, 2008 05:48 PM|brahmg|LINK

     Thank you Anilr, for your prompt response Unfortunently I've run into another snag. In following these instructions http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis7/ It appears that the Failed Request Tracing button is not available to me under the IIS Manager--> Site (proxy in this case) --> Actions ---> Configure Tab. The only option available to me is Limits... Is there another location to turn tracing on, or a way to enable it to show up in my configure pane? I

    Thanks again.

    -Brahm

     

    EDIT: Solved. Needed to install the service, and reboot the server to get Failed Request Tracing to append to my sites... Now let see what the logs say...

  • Re: wildcard host header

    Sep 11, 2008 02:41 PM|brahmg|LINK

     First, thank you to Ruslan & Anil for all your assitance.

    Here is the Goal.

    Setup dev modules, for our users to checkout SVN modules to on the fly to.  All modules must be in the following DIR structure so each user can mount the shared folder (user1) onto local machines to run SVN against, as well as browse/edit the files in each module.

     

    The DIR structure will be something like..

    Inetpub
       - wwwroot
             -user1
                  -module1
                     ~code
                     -images
                     -common
                         ~code
                  -module2
                  -module3
                  -module4
                  -module...
             -user2
                  -module1
                  -module2
                  -module3
                  -module4
                  -module...          

    In IIS I have a base site for each user so user1.devbox.companyname.com, my goal is to be able to have the user type in

    module1.user1.devbox.companyname.com and have it re-write to user1.devbox.companyname.com/module1 (but not redirect) to preserve the dynamic content in the site..so if code is written as <img src=/images/ect.jpg> it will resolve to inetpub/wwwroot/user1/module1/images not inetpub/wwwrot/user1/images/
     

     Here is the Soltuion via ARR/ReWrite

    1) Turn off "Preserve Host Headers" and Turn on "Reverse rewrite host in response headers".

    IIS Manager ---> Application Request Routing ---> Actions ---> Server Proxy Settings

    2) Setup a Proxy site w/no Bindings and in it place your rewrite rule

    IIS Manager ---> Sites ---> "site" (ie proxy) ---> URL Rewrite Module ---> Actions ---> Add Rule

    2) Correct rewrite rule  for this case.

    <rule name="Proxy by host" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
     <add input="{HTTP_HOST}" pattern="^(.*)\.([^.]+\.devbox\.companyname\.com)$" />
      </conditions>
      <action type="Rewrite" url="http://{C:2}/{C:1}/{R:1}" appendQueryString="false" />
    </rule>
     

     (explanation of rewrite rule by Ruslan)

     

    1.     Browser makes a request to http://module1.user1.devbox.companyname.com/images/etc.jpg

    2.     Rewrite rule pattern (.*) matches the url and captures the “images/etc.jpg” into a back-reference {R:1}

    3.     Condition pattern matches the value from the host header and creates two back-references:
      a.     {C:1} contains “module1”
      b.    {C:2} contains “user1.devbox.companyname.com”


    4.     In the rule action the target url is constructed as http://{C:2}/{C:1}/{R:1}, so when all the back-references are expanded the target URL will be http://user1.devbox.companyname.com/module1/images/etc.jpg


    5.     The ARR module forwards the request to this URL and then returns back the response that gets sent to the browser

    6.     To the browser it looks like response came from /images/etc.jpg, even though on the server it actually came from /user1/module1/images/etc.jpg

    Rewrite Map SVN ARR sandboxes

  • Re: wildcard host header

    Oct 17, 2008 07:30 PM|brahmg|LINK

    Just an update.. So I'm running into an issue with Coldfusion Components ignoring this re-write rule. I have no problem hitting the correct folder, but CreateObject locates files via a mydir.myfile structure which for some reason looks to the root directory of the site regardless of where the re-write is pointing to. I know this is a somewhat a of an obscure situation but if anybody has any thoughts I would be grateful

     Thank You

    -Brahm