Previous Next

Thread: wildcard host header

Last post 10-17-2008 7:30 PM by brahmg. 18 replies.

Average Rating Rate It (5)

RSS

Page 1 of 2 (19 items) 1 2 Next >

Sort Posts:

  • 07-19-2008, 12:53 AM

    • jimrPA
    • Top 75 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 59

    wildcard host header

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

     

    thanks

     

  • 07-19-2008, 2:15 AM In reply to

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

    Re: wildcard host header

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

    http://ruslany.net
    Tags:
  • 07-19-2008, 9:38 AM In reply to

    • jimrPA
    • Top 75 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 59

    Re: wildcard host header

    all *.example.com maps to a single website

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

     

    Thanks

  • 07-21-2008, 12:34 PM In reply to

    • DanielVL
    • Top 50 Contributor
    • Joined on 10-07-2006, 6:00 PM
    • Redmond, WA, USA
    • Posts 74

    Re: wildcard host header

    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.

     

    Daniel Vasquez Lopez
    IIS Team
  • 07-21-2008, 2:13 PM In reply to

    • jimrPA
    • Top 75 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 59

    Re: wildcard host header

    OK, I will give it a try. Thanks

  • 07-21-2008, 3:29 PM In reply to

    • jimrPA
    • Top 75 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 59

    Re: wildcard host header

    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?

  • 07-21-2008, 5:01 PM In reply to

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

    Re: wildcard host header

    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:

    • ProxySite with empty host header binding
    • Website1 with host header binding as "example.com"
    • Website2 with host header bidning as "example.org"

    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.

    http://ruslany.net
  • 07-21-2008, 7:38 PM In reply to

    • jimrPA
    • Top 75 Contributor
    • Joined on 06-02-2008, 1:20 PM
    • Posts 59

    Re: wildcard host header

    You nailed it perfect. Thanks :)

  • 09-09-2008, 10:34 PM In reply to

    • brahmg
    • Top 500 Contributor
    • Joined on 09-09-2008, 10:25 PM
    • Posts 10

    Re: wildcard host header

     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.

     

  • 09-10-2008, 1:35 AM In reply to

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

    Re: wildcard host header

    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.

    http://ruslany.net
    Tags:
  • 09-10-2008, 12:33 PM In reply to

    • brahmg
    • Top 500 Contributor
    • Joined on 09-09-2008, 10:25 PM
    • Posts 10

    Re: wildcard host header

    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

  • 09-10-2008, 1:00 PM In reply to

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

    Re: wildcard host header

    1. Open IIS Manager and select server node in the tree view on left hand side
    2. Double click on "Application Request Routing" icon
    3. In the Actions pane on right hand side select "Server Proxy Settings"
    4. In the dialog uncheck "Preserve Host Header"
    http://ruslany.net
  • 09-10-2008, 1:58 PM In reply to

    • brahmg
    • Top 500 Contributor
    • Joined on 09-09-2008, 10:25 PM
    • Posts 10

    Re: wildcard host header

    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

  • 09-10-2008, 2:27 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 10:13 PM
    • Redmond, WA
    • Posts 1,223

    Re: wildcard host header

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

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 09-10-2008, 5:14 PM In reply to

    • brahmg
    • Top 500 Contributor
    • Joined on 09-09-2008, 10:25 PM
    • Posts 10

    Re: wildcard host header

    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/

Page 1 of 2 (19 items) 1 2 Next >
Page view counter