« Previous Next »

Answered Thread: Sub Domain Rewrite

Last post 02-23-2012 7:07 AM by Darrenst. 33 replies.

 

RSS

Page 1 of 1 (34 items)

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 900

    Answered 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 900

    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 900

    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 900

    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 900

    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 900

    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.

  • 07-16-2009, 5:01 PM In reply to

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

    Re: Sub Domain Rewrite

    What's the relative order of the rules?

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

    Re: Sub Domain Rewrite

    Location 1 with 2 have modified and the problem was resolved. But my problem still is not resolved in this post. Please answer it too.

     

    Thanks many ruslan
  • 05-31-2010, 4:17 AM In reply to

    • elphill
    • Not Ranked
    • Joined on 12-07-2009, 6:20 PM
    • Posts 1

    Re: Sub Domain Rewrite

    Hello, Let me know how to do it I have domain say www.mydomain.com and a subfolder mydomain I have pointed www.mydomain.com> mydomain but now the url in godaddy windows hosting shows like this www.mydomain.com/mydomain/default.aspx www.mydomain.com/mydomain/default1.aspx Let me know how to write and the steps My mail id is neel2nil@gmail.com
  • 05-31-2010, 9:55 AM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    This article walks through how to remove the sub-folder from the URL: http://weblogs.asp.net/owscott/archive/2010/05/26/url-rewrite-multiple-domains-under-one-site-part-ii.aspx

    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 10-08-2011, 4:24 AM In reply to

    • om2008
    • Not Ranked
    • Joined on 04-17-2010, 8:37 PM
    • Posts 2

    Re: Sub Domain Rewrite

    Thank you so much.

    Thank you so much.

    Thank you so much.

  • 11-21-2011, 12:24 PM In reply to

    Re: Sub Domain Rewrite

    @ruslany: Seems like you've figured out what I've been looking for like crazy. I copied your example and altered it a bit: What I want is that: http://johndoe.mydomain.nl and johndoe.mydomain.nl redirect to: http://www.mydomain.nl/mypage.aspx?title=johndoe But I get: Not Found HTTP Error 404. The requested resource is not found. btw: I placed the above code as my first rewrite rule in the section Do I need to configure anything extra in IIS?
  • 11-22-2011, 7:58 AM In reply to

    Re: Sub Domain Rewrite

    Hi @ Peter,

    Have you looked at Scott Forsyth's  Blog post

     http://weblogs.asp.net/owscott/archive/2010/05/26/url-rewrite-multiple-domains-under-one-site-part-ii.aspx ?

    AFAIK can post url Rewrite questions at his Blog.

    AFAIK  will follow up with help and suggestions  in the IIS Rewrite Forum.

    Just a suggestion,

    Martin

     

     

    Martin
    Learned "best efforts" come from the Experts in the Community.
    and help with user questions.
    Martin Rasch is Humbled to have received the Award 2011
    for the contributions in the IIS Forums.
    Plase Mark the answers that helps you with your questions
    it sill help the users and Community. Martin

  • 11-22-2011, 1:07 PM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    Thanks Martin for the mention. 

    Hi Peter, I replied to your other post over here: http://forums.iis.net/p/1183351/2003573.aspx#2003573 but it looks like it's waiting for moderation before it's submitted so it should show up later.

    Here's an example which I believe will work for your situation:

    <rule name="subdomain redirect" stopProcessing="true">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^(?!www)(.+)\.mydomain\.com$" />
        </conditions>
        <action type="Redirect" url="http://www.mydomain.com/mypage?username={C:1}" appendQueryString="false" />
    </rule>

    Note that you need to make sure that http://www.mydomain.com/mypage?username=johndoe will work if you visit that page manually, otherwise you'll get a 404 because the target location doesn't exist.

    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 11-23-2011, 3:14 PM In reply to

    Re: Sub Domain Rewrite

    Hi, Yeah, I had the same thing with the moderation. Anyway, thanks for replying so fast. I still get the 404 error though. I added johndoe.mydomain.com to my windows hosts file (since wildcard subdomains arent supported). The full url www.mydomain.com/mypage.aspx?title=johndoe DOES work. Also when I ping my site: johndoe.mydomain.com I get a response from my local server. Now Im thinking the subdomain request is not passed to the correct website (mydomain.com) or am I missing something? Here's what I added:
  • 11-23-2011, 3:29 PM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    Hi Peter,

    Your conclusion sounds right.  Did you add johndoe.mydomain.com as a host header in the site bindings for the same site as you added the URL Rewrite rule?  Since it's a redirect it really isn't critical which site that you added it to as long as the rule and header are on the same site.

    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 11-24-2011, 4:58 AM In reply to

    Re: Sub Domain Rewrite

    Hi Scott, That did fix the problem :) Since the title value should be dynamic, Im assuming that if on my production server I have wildcard DNS enabled, I dont need to add all the subdomains separately? Thanks again also @Martin for pointing me in the right direction
  • 11-24-2011, 10:31 AM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    Hi Peter, what you can do is ensure that you have a dedicated IP for the site and then you can leave the host header blank. That's the IIS equivalent to a wildcard.

    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 11-24-2011, 12:55 PM In reply to

    Re: Sub Domain Rewrite

    Hi Scott, I have a Virtual Private Server with multiple of my sites on it (around 20)...I guess your suggestion would not work in my situation or...? Thanks!
  • 11-24-2011, 10:01 PM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    If all of the other sites have a specific domain then you're ok.  Set your wildcard site with a blank host header and all of the other sites with a specific domain name.  Or, get your host to provide another IP for your wildcard site.  Either option will work well.
    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 11-25-2011, 1:59 PM In reply to

    Re: Sub Domain Rewrite

    Ok, great! Will give that a shot when it goes live :) Thanks again for your help!
  • 12-19-2011, 5:33 AM In reply to

    • QasimRaza
    • Not Ranked
    • Joined on 03-29-2007, 12:41 PM
    • Posts 1

    Re: Sub Domain Rewrite

     Hi ALL,

    I have a domain say www.mydomain.com (website is in ASP.net 4.0 , IIS 7 is there and a static IP address is assigned to the website)

    I have already made url redirect in a way that  if some one enters 

    www.mydomain.com/SOME-WORD/WORD-12356 then 

    it behind the seen redirects user to

    www.mydomain.com/page.aspx?RecordID=12356

    I have done this by making redirect rules in global.asax by using

    System.Web.Routing name space and   routes.MapPageRoute function.

     

    but now i want to have  SOME-SUBDomain.mydomain.com redirects to www.mydomain.com

    Could any one advise how i can do this.

     

     Thanks

    Regards,

    QR

     

     

  • 01-29-2012, 2:06 PM In reply to

    Re: Sub Domain Rewrite

     Sorry to ask for it in this threat but i tried out some of the examples here and its seams not to work if i use it with Joomla 2.5 instead of a sub-folder.

    For Example Joomla 2.5 with different languages and URL Rewrite shows www.domain.eu/de/what-to-do now i would like for "de" german to have shown as a sub-domain in the URL e.g. de.domain.eu/what-to-do-now ect., also for French and English but i think this is not the issue here. Do you may have some suggestion or help what i do wrong? Tanks in advance for your help.

     <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
       <system.webServer>
           <rewrite>
               <rules>
                   <rule name="Joomla! Rule 1" stopProcessing="true">
                       <match url="^(.*)$" ignoreCase="false" />
                       <conditions logicalGrouping="MatchAny">
                           <add input="{QUERY_STRING}" pattern="base64_encode[^(]*\([^)]*\)" ignoreCase="false" />
                           <add input="{QUERY_STRING}" pattern="(&gt;|%3C)([^s]*s)+cript.*(&lt;|%3E)" />
                           <add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                           <add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
                       </conditions>
                       <action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
                   </rule>
                   <rule name="Joomla! Rule 2">
                       <match url="(.*)" ignoreCase="false" />
                       <conditions logicalGrouping="MatchAll">
                         <add input="{URL}" pattern="^/index.php" ignoreCase="true" negate="true" />
                         <add input="{URL}" pattern="/component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$" />
                         <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                       </conditions>
                       <action type="Rewrite" url="index.php" />
                   </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>
               </rules>
           </rewrite>
       </system.webServer>
    </configuration>

     

  • 01-30-2012, 10:47 AM In reply to

    • OWScott
    • Top 50 Contributor
    • Joined on 08-12-2002, 5:25 PM
    • North Carolina
    • Posts 233

    Re: Sub Domain Rewrite

    Hi idontknow12,

    Something like this should work. 

    <rule name="Subdomain Language">
        <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^de\.domain\.eu$" />
            <add input="{URL}" pattern="^de/" negate="true" />
        </conditions>
        <action type="Rewrite" url="/de/{R:0}" />
    </rule>

    Add the de.domain.eu binding to the same site, then it will confirm that the domain is de.domain.eu and that the URL doesn't already start with /de/.  If that happens then it will serve up the site from /de/ instead of the root.

    It's possible to merge your three language rules into one but probably easier to just create three rules for each and replace 'de' with 'fr' or 'en'.

    Scott Forsyth
    Microsoft MVP - IIS
    ASPInsider

    ORCS Web, Inc
    www.orcsweb.com
  • 02-23-2012, 7:07 AM In reply to

    • Darrenst
    • Not Ranked
    • Joined on 06-14-2007, 1:52 PM
    • Posts 1

    Re: Sub Domain Rewrite

     Sorry Guys.

    Spent an hour on the same rule and it still is not working as expected. 

    I have two domain names. 

    www.domain.co.uk

    blog.domain.co.uk

    In order for google not to hammer me with Duplicate Content. I need to Rewrite anything that comes from:

    blog.domain.co.uk

    to:

    www.domain.co.uk/blog

    This also need to apply to urls with subordinates like:

    blog.domain.co.uk/2012/embedding-multiple-youtube-videos-in-your-website.aspx

    to:

    www.domain.co.uk/blog/2012/embedding-multiple-youtube-videos-in-your-website.aspx 

     

    Can this be done because everything I try redirects to the homepage not the blog .

     

    Thank you,

Page 1 of 1 (34 items)