logo

Customise Content Based On Domain

One of the reasons I've been playing with DNS recently is that I've been testing a client's website I'm working on. It's a fairly large site and content is customised for each office location. Location is derived from the host name of the URL. For example www.sydney.company.com.au (or just sydney.company.com.au) is for the Sydney office and www.newcastle.company.com.au (yep, they have one too!) is for Newcastle's office. Etc etc.

There's a list of about 100 or so offices that need to be handled. Now, because I am developing remotely and using my own server, it's hard to really test this functionality in its true environment. So, what I've done is add a company.com.au Virtual Domain to my DNS server. Because my PCs try my own DNS records before the internet's I can over-ride the global DNS. When I visit www.company.com.au now I see the site I am working on "locally" and not their current site.

To this Virtual Domain I then add host records for a few example offices. E.g: www.newcastle, newcastle, www.sydney. sydney, www.canberra, canberra. They all point to the same IP address, of my Domino dev server. On the Domino server I create a new Web Site document in the Domino Directory, as below:

Web Site Document

All these host names point to the one database that acts as the homepage. On every form is a Computed For Display field, with the following formula, that extracts the office name from the URL.

@ReplaceSubstring( Server_Name; "www":"company.com.au":"."; "" )

This field is then available whenever content is required based on office location. Works a treat so far.

Don't you just love @Functions! So simple and so effective. Originally I had coded the following, which involved three times as many @Functions.

@Implode( @Replace( @Explode( Server_Name; "." ); "www":"company":"com":"au"; "") )

I was going to give you guys the challenge to simplify it, but thought I'd better save face and have a go myself first. If you can make it any simply than one @Function I'd be happy to hear about it ;o)

Comments

  1. Jake,

    A slight problem with the @ReplaceSubstring function you've used .. what happens if the Server_Name's value is of mixed-case?

    Here's what I would use :

    @Middle( @LowerCase(Server_Name) ; "w." ; ".company" ) ;

    • avatar
    • Jake
    • Tue 20 Jul 2004 08:17

    Good point Richard. It seems that Domino translates all incoming hostnames to lowercase by default though. The value of Server_Name is always lowercase.

    There's a problem with your formula as well. It would work but not when the www. is dropped from the domain (which is an option for this setup).

    • avatar
    • Richard
    • Wed 21 Jul 2004 03:42

    Thanks for the tip about Server_Name always being lowercase.

    However, I'm not to familiar with the domain name syntax. - What is the maximum number of "." in a domain name? Are you allowed as many as you like?

    • avatar
    • Jake
    • Wed 21 Jul 2004 03:54

    I can't say for sure Richard but I've seen some with three or four sub-domains listed. eg. sales.london.companyuk.company.com.au

    I did a quick Google to find an answer but it's one of those questions that it's hard to word properly. "Maximum number of sub domains in a URL"?

    • avatar
    • laurens
    • Wed 21 Jul 2004 05:35

    couldn't you achieve the same with creating website documents in the Domino Directory?

    • avatar
    • Jake
    • Wed 21 Jul 2004 05:42

    Not sure what you mean Laurens. That's what this entry is talking about - creating website documents.

    • avatar
    • zomek
    • Tue 27 Jul 2004 04:31

    Maybe my tip won't win the Shortest Formula Ever Contest, but I would advise using something like that:

    @Replace(@MiddleBack(AdresDNS; ".company.com.au"; "."); "www"; "")

    You're sure that office name is one of the DNS address'es segment and it's fourth segment counting from root. But why you assume that in the future they will not want to add some servers in these offices? For example:

    www.finance.sydney.company.com.au

    development.sydney.company.com.au

    At the end you should take care of segment coming from service type. But you should be prepared for "weird" addresses like:

    www.sydneywww.company.com.au

    which isn't the same as:

    www.sydney.company.com.au

    Maybe "www" doesn't seem to fit here, but "wap" is more probable to occure in city name and could be more dangerously.

    And with Richard's Q about number of dots in DNS names - AFAIK there is no such constraint (why should it be?!). You can create your DNS structure to have zillions of levels ;)

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Tue 20 Jul 2004

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content