How to: Mulitple sites on one account

Discussion in 'Site Programming, Development and Design' started by elitemike, Jul 23, 2010.

  1. Finally we have the proper way to have sites in subdomains thanks to Scott Forsyth. Scott spent a lot of time working through the issue. I started out by following his blog posts URL Rewrite – Multiple domains under one site but it turns out he wasn't accounting for all things. He will update the post with what he learned from working on my site

    For what I'm going to show, assume that site1, site2, and site3 are subfolders in your root that have been set as applications. Assume that the domains are site1.com, site2.com and site3.com. Each site will have rewrite rules to handle the outbound urls, which is important when dealing with .net and especially ajax. In the root I have a web config that just contains the rules to handle the domain pointing. I chose to not have any sites reside in the root to make the web config simple.

    Root Web.config

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <clear />
                    <rule name="Canonical Host Name Site 1" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^www\.site1\.com$" />
                        </conditions>
                        <action type="Redirect" url="http://site1.com/{R:1}" />
                    </rule>
                    <rule name="Canonical Host Name Site 2" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^www\.site2\.com$" />
                        </conditions>
                        <action type="Redirect" url="http://site2.com/{R:1}" />
                    </rule>
                    <rule name="Canonical Host Name Site 3" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^www\.site3\.com$" />
                        </conditions>
                        <action type="Redirect" url="http://site3.com/{R:1}" />
                    </rule>
    
                    <rule name="Site 1" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?site1\.com$" />
                            <add input="{PATH_INFO}" pattern="^/site1($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\site1\{R:0}" />
                    </rule>
                    <rule name="Site 2" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?site2\.com$" />
                            <add input="{PATH_INFO}" pattern="^/site2($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\site2\{R:0}" />
                    </rule>
                    <rule name="Site 3" enabled="true" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                            <add input="{HTTP_HOST}" pattern="^(www\.)?site3\.com$" />
                            <add input="{PATH_INFO}" pattern="^/site3($|/)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="\site3\{R:0}" />
                    </rule>
    
                </rules>
            </rewrite>
            <urlCompression doStaticCompression="true" doDynamicCompression="true" />
        </system.webServer>
    </configuration>
    Site Rules for site1.com

    Code:
    <rewrite>                        
                <outboundRules>
                    <rule name="Outgoing - URL paths" preCondition="Not .axd files" enabled="true">
                        <match filterByTags="A, Form, Img, Input, Link, Script" pattern="^(?:site1|(.*//[_a-zA-Z0-9-\.]*)?/site1)(.*)" />
                        <conditions>
    
                        </conditions>
                        <action type="Rewrite" value="{R:1}{R:2}" />                    
                    </rule>
                    <rule name="response_location URL">
                        <match serverVariable="RESPONSE_LOCATION" pattern="^(?:site1|(.*//[_a-zA-Z0-9-\.]*)?/site1)(.*)" />
                        <conditions>
                            <add input="{URL}" negate="true" pattern="\.axd$" />
                        </conditions>
                        <action type="Rewrite" value="{R:1}{R:2}" />
                    </rule>
                    <rule name="response_location querystring">
                        <match serverVariable="RESPONSE_LOCATION" pattern="(.*)%2fsite1(.*)" />
                        <conditions>
                            <add input="{URL}" negate="true" pattern="\.axd$" />
                        </conditions>
                        <action type="Rewrite" value="{R:1}{R:2}" />
                    </rule>
                    <preConditions>
                        <preCondition name="Not .axd files">
                            <add input="{URL}" pattern="\.axd" negate="true" />
                        </preCondition>
                    </preConditions>
                </outboundRules>
            </rewrite>
            <urlCompression doStaticCompression="false" doDynamicCompression="false" />
     
  2. Omgg thank you so much =d
     
  3. did it work for you?
     
  4. it worked perfectly, no troubles setting up and no now troubles with ASP.NET AJAX

    thank you so much :)
     
  5. Thanks - this works nicely.

    When I switched to Winhost from Webhost4life, I was a little surprised that I couldn't just setup multiple ASP.NET applications on my account and have domains routed directly - hence the need for these tricks.

    So I have this in place, and now my sites are alive, but the URL's aren't what I'd like them to be - i.e. http://blog.myname.com get mapped to http://blog.myname.com/blog_prod using this <rewrite /> mechanism (blog_prod is the root directory on my account). That gets me functional, but all of my permalinks are bunk now. I was hoping there would be a way to use <rewrite /> to keep the incoming URL as the visually displayed URL, but redirect the request pipeline to another location.

    Kinda seems like we're using URL Rewriting backwards in this case. Typically rewriting is about turning ugly URL's into something pretty, but keeping the application functioning as if the ugly URL is being processed. In this case, we're turning pretty URL's into ugly ones because ugly is what's needed to function.

    I can live with this, but I'd much rather have http://blog.myname.com route to my blog_prod subdirectory without my users having to know about it.
     
    Last edited by a moderator: Oct 14, 2015
  6. OK - scratch all that. I don't think I understand what this example was showing and I certainly didn't apply it right to my scenario. This absolutely will give you the routing/mapping as well as the rewriting capabilities I was saying I wanted.

    Here's a more concrete example that will hopefully help someone else that comes across this.

    Here's my example - you have a domain name "acme.com" and you want to map it to a subdirectory on your account named "dir-acme", you'll want to first create a Web.config file in the root of your Winhost account directory that looks like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <clear />
    
            <rule name="amc-redirect" enabled="true" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" pattern="^www\.acme\.com$" />
              </conditions>
              <action type="Redirect" url="http://acme.com/{R:0}" />
            </rule>
    
            <rule name="amc-redirect-rewrite" enabled="true" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" pattern="^(www\.)?acme\.com$" />
                <add input="{PATH_INFO}" pattern="^/dir-acme($|/)" negate="true" />
              </conditions>
              <action type="Rewrite" url="/dir-acme/{R:0}" />
            </rule>
            
          </rules>
        </rewrite>
        <urlCompression doStaticCompression="true" doDynamicCompression="true" />
      </system.webServer>
    </configuration>
    
    The next step is to setup your outbound rules. Not doing this properly will result in the HTML your site spits out to have hyperlinks to the old/bad/ugly URL's. So, put this in your applications Web.config file that's residing in dir-acme\.

    Code:
    <?xml version="1.0"?>
    <configuration>
    
    
    	<!--  YOUR CONFIG STUFF UP HERE... OMITTED FOR BREVITY -->
    	
      <system.webServer>    
        <rewrite>
          <outboundRules>
            <rule name="Outgoing - URL paths" preCondition="Not .axd files" enabled="true">
              <match filterByTags="A, Form, Img, Input, Link, Script" pattern="dir-acme(.*)" />
              <conditions>
    
              </conditions>
              <action type="Rewrite" value="{R:1}" />
            </rule>
            
            <preConditions>
              <preCondition name="Not .axd files">
                <add input="{URL}" pattern="\.axd" negate="true" />
              </preCondition>
            </preConditions>
          </outboundRules>
        </rewrite>
        <urlCompression doStaticCompression="false" doDynamicCompression="false" />
      </system.webServer>
    </configuration>
    

    And if this syntax is completely foreign to you, this is a good reference: http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/
     
    Last edited by a moderator: Oct 14, 2015
  7. I'm about to test this out... very surprised and disappointed I can't have multiple domains on my one account transparently. Other asp.net hosts are offering this afterall.

    So it sounds like the workaround is going to force http://www.newdomain.com
    to a subdiretory like http://www.newdomain.com/newdomain. Bummer if true.

    Do you guys actually see the redirect happening?

    How stable is this? What about things with relative path in code? No issues?

    thanks.
     
  8. these rules handle relative paths. Stability is just fine. Companies like webhost4life are doing the same exact thing as these guys are.
     
  9. Thank you!

    I just wanted to say, thank you for writing that post. I have been fighting with URL Rewrite for the past week. I even used the same blog post you found, and had a few issues that I could not find a solution for.

    In any case, my site appears to be working as I want, so thank you very much.
     
  10. elimtemike - thanks for the post. Much needed in lieu of Winhosts - lack of transparency on this front, during purchase. You're a life saver! :)

    1. Will this work with silverlight websites as well
    2. Is your later post a correction to the first/earlier post, or is it for sub-directory
    3. Lastly, does the rewrite (2nd set of xml) go in to another web.config, and does this new web.config (for 2nd site) reside in the sub directory with the 2nd site, could you post a sample web.config file please.
    4. Do we still need the application pointer to be mapped accordingly in the Cpanel, or what else is required in the CPanel?
     
  11. Ray

    Ray

    Last edited by a moderator: Oct 14, 2015
  12. Mike, I removed the Ajax functionality for now. And, its helped. I ll put it back later.

    Before that, can you tell me where does the 2nd XML rewrite rules file should be placed - I assumed it would be in a web.config, in the application folder for the site2.com.


    I am getting errors, and wondering if I made a mistake by putting only the rewrite rules that elite posted. Do, I need the other content in the web.config, if I have a sample it would be much easier.
     
  13. Ray

    Ray

    That will depend on where the application calls are being made. If you need the root to display the rule it will be on the roots web.config file. If you need it to on a subfolder where it is hosting its own ASP.Net web application, then it would be within the subfolders web.config file.
     
  14. Ok great, so my site2.com is in a subfolder and I put the rewrite (xml) there.

    Do I just tack on the rewrite rules to the end of the default web.config, - where in the web.config do these rules go, or are they just separate nodes (for e.g. like http handler config are separate nodes). I was looking for a sample to find this.

     
  15. Ray

    Ray

    The rewrite element will go under the system.webServer section. You will need to make sure you type it correctly, remember this is an XML base file so it is very temperamental to capitalizations and spaces. If you are new to web.config files, then I suggest you use the URL Rewrite module in IIS 7 Manager. It's a little easier to use and it is GUI base and it automatically implements the codes for in the web.config file. Simply download IIS 7 Manager and configure it to connect to our server then look for the button/module URL Rewrite.

    http://support.Winhost.com/KB/a628/using-the-microsoft-iis-70-manager.aspx

    You may also want to look at some documentations on URL Rewrite in IIS 7 before you get started. Reading up on it before you get started can help avoid a lot of headaches.

    http://weblogs.asp.net/owscott/arch...-hosting-multiple-domains-under-one-site.aspx

    http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

    http://learn.iis.net/page.aspx/465/...nfiguration-reference/#Rewrite_Rules_Overview
     
    Last edited by a moderator: Oct 14, 2015
  16. Do I understand this correctly?

    MYSite is hosted on Winhost

    CURRENTLY, if I want to host OtherSite1.com and Othersite2.com there as well, I can use other redirect methods, but visitors to each of the sites will see the following in the address field of their browsers:

    - MySite.com
    - MySite.com/OtherSite1
    - MySite.com/OtherSite2

    BUT WITH THESE REDIRECT SCRIPTS, visitors to each of the sites will see the them in a way that's identical to how they would appear if they were hosted tough separate accounts? :

    - MySite.com
    - OtherSite1.com
    - OtherSite2.com

    It works this way for DNN sites as well?

    But if any of the sites employ Ajax, there are additional scripting considerations?

    Thanks for clarifying this to me,
    Bill
     
    Last edited by a moderator: Oct 14, 2015
  17. Ray

    Ray

    Yes, you can incorporate the URL rewrite rules so that you can force additional domain names (domain pointers) to redirect to its own subfolder but keep the URL..

    - OtherSite1.com
    - OtherSite2.com

    As you stated it does require a little more coding but it can be done.
     
  18. Thanks again Ray. That's very cool!
     
  19. Hello elitemike,

    We are new to handling this issue, so we ask you please, if you can add the code for the 'Site Rules for site2.com', as you did for 'Site Rules for site1.com'.

    We make this request because our group does not handle well your English language, and we do not want any mistakes, or at least that the errors are minimal and easy to detect.

    We hope you understand us.

    Thanks

    Translated http://translate.google.es/

    :D
     
  20. Hello

    We tested with the example proposed by "kbrowns" and has served us well.

    The only detail we have seen, and which we wish someone would clarify this question:

    Why when we write in our browser, for example http://www.anydomain.com, it always reset to http://anydomain.com and always remove the "www."?

    :confused:

    Thanks
     
  21. Ray

    Ray

    Not sure. If you can paste the rule on this thread we can review it a little more closely.
     
  22. I'm not very experienced with this stuff....

    Right now I have 'www.site1.com' setup and working great. I'm trying to add 'www.site2.com'.

    I went to GoDaddy.com and setup the DNS for site2 to match what I have for site1.com (the one that works). I tried modifying my web.config to match what was posted above - but when I go to site2.com I get a generic looking website error:

    Web Page is Unavailable

    We are very sorry.

    The web page you are trying to reach is unavailable.

    Please contact the Website Administrator.

    We apologize for the inconvenience.​


    I have created a folder /site2/ and put all of the site2 content in that folder; I'm not sure where that error page is coming from. Can someone give me some direction?
     
  23. Sorry - I can't seem to edit my post; but I see what I've done wrong. My bad.
     
  24. Glad you got it worked out.
     
  25. http://forum.Winhost.com/showthread.php?t=2838&highlight=sys+undefined

    I've got the exact same error messages described in the above thread.

    I was testing a page in a subfolder that has been set as "Application Starting Point", also created domain pointer for xxyyzz.org . A default.aspx page in that subfolder loads fine when I browse to xxyyzz.org (but the ajaxtesting.aspx having expandable/collapsalbe ajax controls are not functional and the 'Sys is undefined' messages are poping up.

    What am I missing? ajax toolkit does work in subfolder app, doesn't it? what part of the rewrite rule I should double check? Help, anyone?! ajax toolkit is not working!

    I have framework 3.5, the AjaxControlToolkit.dll is of version 1.0.20229, it works fine in local host.
     
    Last edited by a moderator: Oct 14, 2015
  26. OK, so I double checked my rewrites and changing all values inside the curly bracket to consistently reflect R:0 rather than R:1 and it WORKS. That means Ajax toolkit works in sub-folder (a new site)

    Now I need to deal with the path to a style sheet, sometimes it loads perfectly fine, sometimes it can't locate that css. Does anyone has a permanent fix for this kind of reference?

    I have tried to replace ../ with ~/ but doesn't make any difference.

    http://weblogs.asp.net/lkempe/archive/2007/08/04/asp-net-ajax-and-url-rewriting-issue.aspx:D
     
  27. I am sorry but I find this a very unacceptable solution to hosting multiple domains under one hosting account.

    Perhaps this is an issue with IIS 7.0, I will need to do more research, but having run my own servers on IIS 5.1 platform this was all handle in the orginal site setup and each site ran in seperate folder. Only issue there was never run site in wwwroot, always create subfolder.
     
  28. Like most limitations, we impose this one primarily for quality of service reasons. If we allow any account on a server to create new root directories (new sites), we have no way of controlling site density on the server.

    There is a limit to how many sites can run on a server while still maintaining acceptable performance. If we control creation of sites, we can control that density. If we do not, then you can run into issues where there are 10,000 sites running on a server, performance is negatively impacted, and everyone is unhappy.

    There are other management and quota issues, but the primary concern is overall server health and performance. That is always our primary motivation.

    I understand that from the point of view of a consumer, you want fewer limitations. Who wouldn't? But the fewer the limitations, the more unwelcome variables present themselves. We don't want your experience to be degraded by your neighbors on the server. In order to provide stable and reliable service, certain limitations are a necessary evil.
     
  29. Server Health

    Seems to me this configuration would create more task for the server not less. It requires a process run the script in order to present the site.

    There is the process that ran just before this one at a server level that resolves the DNS to a directory on the server. Now there is an additional process that must run to again resolve that domain name to the appropriate directory. Makes no sense.

    Appears to me essentially you are just saying one web site per account. The web hosting market being the competative one it is, demands you offer multiple sites under one account. But the implementation of this ability I am certain discourages the operation of multiple domains in one account.

    If I create an addition account to run another domain, does this account get set up on another server of the same server with simply the DNS resolving to the new directory.

    I am just happy I only signed up for a test period of 90 days before moving my sites to your service.
     

Share This Page