« Previous Next »

Thread: Sub Domain Rewrite

Last post 07-17-2009 2:34 AM by sadegh-shad. 16 replies.

Average Rating Rate It (5)

RSS

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

Sort Posts:

  • 03-04-2009, 11:15 AM

    • sfraser
    • Not Ranked
    • Joined on 03-04-2009, 4:03 PM
    • Posts 4

    Sub Domain Rewrite

    Been trying to create a rule to allow sub domains to be added to domains, in which it would link to a folder inside the www folder

    I have this rule and it just returns bad request, but if its changed to redirect it works fine, just the address is incorrect.

    <rule name="SubDomain" stopProcessing="false">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.mine\.co\.uk$" />
                        </conditions>
                        <action type="Rewrite" url="http://mine.co.uk/{C:1}" />
                    </rule> 

    instead of sub.mine.co.uk

    it would be mine.co.uk/sub

    I understand that is how redirect works, so why does the rewrite return bad request?


     

  • 03-04-2009, 1:03 PM In reply to

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

    Re: Sub Domain Rewrite

    When you use full URL with the Rewrite action (i.e. url that starts with http://), that triggers URL rewriter to proxy the request to that URL instead of rewriting. Proxy functionality is done by using Application Request Routing module. You most probably do not have that module installed, that's why you get bad request errors.

    If you just want to rewrite then you should use just URL path, e.g:

    <rule name="SubDomain" stopProcessing="false">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.mine\.co\.uk$" />
                        </conditions>
                        <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule> 

    http://ruslany.net
  • 03-04-2009, 1:22 PM In reply to

    • sfraser
    • Not Ranked
    • Joined on 03-04-2009, 4:03 PM
    • Posts 4

    Re: Sub Domain Rewrite

     thanks that works a treat.

  • 03-12-2009, 6:26 PM In reply to

    Re: Sub Domain Rewrite

    How about the reverse of this?  How can I point:

    www.domain.com/subdomainname

    to

    subdomain.domain.com

    and making sure that any subsequent pages after the /subdomainname also maps correctly such as:

    www.domain.com/subdomainname/page1.aspx

    would map to

    subdomain.domain.com/page1.aspx

     

    Any help would be appreciated.

  • 03-13-2009, 2:38 PM In reply to

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

    Re: Sub Domain Rewrite

    When you say "point to", do you mean rewriting or redirection. I.e. when user in the browser clicks on the link to www.domain.com/subdomain and gets a response, what URL should be in the browser's address bar?

    http://ruslany.net
  • 03-16-2009, 12:26 PM In reply to

    Re: Sub Domain Rewrite

    I meant "rewrite".  The URL should remain www.domain.com/subdomain in the browser.

     

     

  • 03-17-2009, 1:24 PM In reply to

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

    Re: Sub Domain Rewrite

    In this case there are two possible situations:

    1. If the subdomain.domain.com is bound to the same web site as www.domain.com then you can just have a rewrite rule that strips off the "/subdomain" part from the URL path.
    2. If the subdomain.domain.com is a separate web site, then you will have to use Application Request Routing module as a reverse proxy to that web site.
    http://ruslany.net
  • 03-23-2009, 3:00 PM In reply to

    Re: Sub Domain Rewrite

    It's the same IIS site.  However, subdomain.domain.com shows differently than www.domain.com. And the web app uses the "subdomain" to determine what to show.  So, if I just strip it off, the app will see "www" and will show the "www" view.  I hope that makes sense.  Maybe you're #1 option is what I need but what would I put in my web.config?

  • 03-25-2009, 8:12 PM In reply to

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

    Re: Sub Domain Rewrite

    What does web application use to determine the subdomain? Does it look at the HTTP_HOST server variable? If yes, then option #1 will not work, because the HTTP_HOST header will be still set to www.site.com after rewriting.

    http://ruslany.net
  • 07-05-2009, 2:46 AM In reply to

    Re: Sub Domain Rewrite

     it's not work on local

     how do i?

  • 07-08-2009, 12:15 AM In reply to

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

    Re: Sub Domain Rewrite

    Could you provide more details on what does not work and what you are trying to do? If you post your rewrite rule here that will also help.

    http://ruslany.net
  • 07-10-2009, 4:17 PM In reply to

    Re: Sub Domain Rewrite

     thanks ruslan

    it's resolved.

    now how do i when user typed domain.com/news/default.aspx redirect it to news.domain.com/default.aspx ???

     

    thanks

  • 07-13-2009, 5:03 AM In reply to

    Re: Sub Domain Rewrite

     for redirect i'm used this rule

     <rule name="Redirect subdomain" stopProcessing="true">
                        <match url="^([.0-9a-z.]+)" />
                        <conditions>
                            <add input="{HTTP_HOST}" negate="true" pattern="^(?!www)(\w+)\.domain\.net$" />
                        </conditions>
                        <action type="Redirect" url="http://{R:1}.domain.net" redirectType="Permanent" />
                    </rule>

     this rule is correct? if correct changes this need to work correct for this?

    domain.net/f1/f2/f3/../fn

    thanks

  • 07-14-2009, 7:30 PM In reply to

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

    Re: Sub Domain Rewrite

    Try this maybe:

    <rule name="Redirect subdomain" stopProcessing="true">
      <match url="(\w+)/(.*)" />
      <conditions>
         <add input="{HTTP_HOST}" pattern="^domain\.net$" />
      </conditions>
      <action type="Redirect" url="http://{R:1}.domain.net/{R:2}" redirectType="Permanent" />
    </rule>

    http://ruslany.net
  • 07-15-2009, 1:50 PM In reply to

    Re: Sub Domain Rewrite

     Oh, like that does the final problems.

    Now I have one other problem. When I use this rule, another rule that used for rewriting page news don't work and gives page not found message. Now I do?

    news rewrite rule

    <rule name="Rewrite news">
     <match url="^news/([.0-9.]+)[.]([.0-9a-z.]+).artx" />
     <action type="Rewrite" url="news/default.aspx?id={R:1}&amp;t={R:2}" />
    </rule>

     

    subdomain rule

     <rule name="Rewrite subdomain" stopProcessing="false">
     <match url="(.*)" />
     <conditions>
      <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.net$" />
     </conditions>
     <action type="Rewrite" url="{C:1}/{R:1}" />
    </rule>

     

    Really thank you.

Page 1 of 2 (17 items) 1 2 Next >
Microsoft Communities