Alongside developing lots of different websites in Drupal, we also maintain and administer a number of different servers. In this role we occasionally end up managing a number of different domain names. It struck us as interesting that many people don’t really understand the difference between using the domain with or without www, for example www.willhallonline.co.uk and willhallonline.co.uk. They are technically two different subdomains of willhallonline.co.uk, however, it has to be stressed that they are different. You can even extend these to be routed to different locations (servers) or websites.

Using Apache you can use .htaccess files to maintain and rewrite domains, however, as nginx does not have direct access to routing, and running it through PHP to use header(‘Location: http://www.willhallonline.co.uk'); would introduce unnecessary system time. It can be done in the routing on nginx… speedy! Brilliant!

Although it is very unlikely that users will actually notice, or that Google will penalise you for having duplicate content (which has been sighted as a reason in the past) it can be useful to only use one domain rather than two.

This example shows how you can re-route both non www. and totally separate domain iamwillhallonline.co.uk to www.willhallonline.co.uk.

server {
    server_name willhallonline.co.uk www.iamwillhallonline.co.uk iamwillhallonline.co.uk;
    return 301 $scheme://www.willhallonline.co.uk$request_uri;
}

As you can see I have also included some extra loveliness in the return. Lets break it down:

You can also use the redirect to redirect a domain to a specific landing page which can be useful if you are consolidating domains or have a specfic landing page that you have a more appropriate url for. As you can see the redirect sets a specific location about/team.

server {
    server_name www.willhallonlineteam.co.uk willhallonlineteam.co.uk;
    return 301 $scheme://www.willhallonline.co.uk/about/team;
}

Hope you find it useful.