Multiple domains, single site, different stylesheets...

Discussion in 'Web Design' started by Phreaddee, Oct 2, 2012.

to remove all ads.
  1. Phreaddee

    Phreaddee Super Moderator Staff Member

    Messages:
    1,978
    So I've been working on this stupidly large site for a training company (apprentices/trainees/etc..) recently, where they have up to now had 27 regional offices, all with their own domains, and websites, blah blah...

    I've conglomerated this all into one site/design and we are rolling it out with a brand refresh and marketing and all that jazz. currently when you go to the website you can click the regions page and then choose what region you are from, or want information about. this changes the header to have the regional office's name and telephone number, their contact info to display first in the list, and their own customised about page, otherwise the info is generic.

    this is easy enough via...
    Code:
    onclick="setActiveStyleSheet('new-stylesheet-name-goes-here');
    on a link.

    the "brand" however has been around for 30 years and they have all had a web presence for many years now, and so would like to keep all the domains active rather than just pointing to the main site domain.

    my question is I would like to set a stylesheet redirect up based on the domain typed in the browser. so domainA, DomainB and DomainC all point to the same hosting, but A,B and C all get the customised header, contact and about page relevant to that domain.
    as it stands you can go to domainA, choose regionC, close your browser, and reopen on DomainB and it will still show you the details as if it was domainC.

    I figure I have to use
    Code:
    window.location.host
    
    and some form of if else statement but I'm not 100%. if anyone has any ideas please let me know??

    and yes I know you will have a laugh at this chris as I've asked similar questions in the past.
    (although I was pretty proud of my select box -> radio buttons effort.)

    oh and no php crap. its an aspx site
     
    Last edited: Oct 2, 2012
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    Serverside is much easier. Include a different stylesheet that is dependent on the hostname that was requested.

    Code:
    Select Case HttpContext.Current.Request.Url.Host
         Case "hostname"
              Response.Write "<link rel=" & Chr(34) & "stylesheet" & Chr(34)
              Response.Write " href=" & Chr(34) & "path to different stylesheet" & Chr(34)
              Response.Write ">" & Chr(10) & Chr(13)
         Case Else
              Response.Write "<link rel=" & Chr(34) & "stylesheet" & Chr(34)
              Response.Write " href=" & Chr(34) & "path to usual stylesheet" & Chr(34)
              Response.Write ">" & Chr(10) & Chr(13)
    	  
    End Select
    
     
  3. Phreaddee

    Phreaddee Super Moderator Staff Member

    Messages:
    1,978
    well funnily enough their was a mix up with the hosting company and they have not added the extra domains into the site, but set up a redirect.

    they also aren't too keen to help me out on this one, but have given me access to the web.config file this is what is there now...

    Now is this even possible to do now? but before the redirect? I'm really at a loss here with this, and whilst I understand (to some degree) what you've written here chris I'm wondering if because this is an XML file I don't actually need the chr(34) bits n bobs? or If I'm just kidding myself that this can even be done?

    have I been shot in the foot with this permanent redirect therefore meaning any "changes" made based on the root domain would be later changed anyway as it redirects to another?

    Edit: this is setup on a VM running IIS7.
     
    Last edited: Oct 3, 2012
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,675
    The code I gave doesn't go in the web.config and YES, if you are redirecting you cannot use a different stylesheet because the hostname will always be the same.


    Do you not have control panel or RDP access to the VM? Running multiple hostnames on a single "server" is simply a matter of adding host headers for each name to the site configuration. http://technet.microsoft.com/en-us/library/cc753195(v=ws.10).aspx

    The code I gave goes in the <head> section of the document and writes a stylesheet reference into the document, the chr(34) are there to insert the double quotes around the values, because ASP and .NET have no real means of "escaping" the quote marks. in C# you can use ""value"" but it is all too easy to miss one out and have it throw an exception and I've have long since been in the habit of using chr(ascii-code) to insert control characters.
    You of course may already know that but other readers may not.
     

Share This Page