Someone tells you a website to visit - "go to wellhousemanor.co.uk" they say. And you'll naturally add "www." in front of it, calling up www.wellhousemanor.co.uk rather than wellhousemanor.co.uk ... or perhaps you won't.
Web servers are normally set up by default to respond to a single specific host name - either wellhousemanor.co.uk or www.wellhousemanor.co.uk in the example that I've used above. But then, if you
a) Configure your DNS records for both www.wellhousemanor.co.uk and wellhousemanor.co.uk to point to the same server and
b) add a ServerAlias as well as a ServerName in you virtual host definition:
ServerName www.wellhousemanor.co.uk
ServerAlias wellhousemanor.co.uk
you can set up a single web site to respond seamlessly to either name (with or without) the "www.". This process can be taken further so that the same host can respond in the same way to other domain names by adding further DNS records and further ServerAlias-es.
I will question how wise it is to do a lot of this, as your content may end up being "diluted" across a lot of domains as far as search engines are concerned, and you may end up loosing visibility. Beware!
Ironically, there may be occasions where you have two host names pointing at the same virtual host, and you want to know which was the one used to access your site by your visitor.
• In a PHP program, you can use the $_SERVER[HTTP_HOST] variable (and there will be equivalents in other languages / Frameworks
• Within your Apache configuration, you can refer to %{HTTP_HOST} - for example, if www.wellhousemanor.co.uk and wellhousemanor.co.uk shared the same virtual host, the following lines in your .htaccess file would allow you to divert requests for anything in the /info directory to another site, provided that the original call was to wellhousemanor.co.uk rather than to www.wellhousemanor.co.uk
RewriteEngine On
RewriteCond %{HTTP_HOST} ^wellhousemanor.co.uk$
RewriteRule ^/info http://www.wellho.net/ [L]
This technique - not well documented elsewhere as far as I can see - may be a great help if you're in the process of merging domains, but still have one or two rather obscure sections of your site / the domains which are still to be integrated under a single name.
(written 2012-01-04, updated 2012-01-07)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
H112 - PHP - Further Web Page and Network Handling [220] When to use Frames - (2005-02-19)
[314] What language is this written in? - (2005-05-17)
[345] Spotting a denial of service attack - (2005-06-12)
[356] Sudoku helper or sudoku cheat - (2005-06-23)
[372] Time calculation in PHP - (2005-07-08)
[376] What brings people to my web site? - (2005-07-13)
[410] Reading a news or blog feed (RSS) in your PHP page - (2005-08-12)
[425] Caching an XML feed - (2005-08-26)
[443] Server side scripting of styles to suit the browser - (2005-09-12)
[451] Accessing a page via POST from within a PHP script - (2005-09-26)
[484] Setting the file name for a downloaded document - (2005-11-03)
[537] Daily Image Santafied - (2005-12-22)
[542] Morning image, afternoon image - (2005-12-26)
[565] Using PHP to output images, XML, Style sheets, etc - (2006-01-15)
[603] PHP - setting sort order with an associative array - (2006-02-13)
[675] Adding PHP tags to an old cgi program - (2006-04-08)
[767] Finding the language preference of a web site visitor - (2006-06-18)
[789] Hot answers in PHP - (2006-07-02)
[847] Image maps for navigation - a straightforward example - (2006-08-28)
[904] Of course I'll tell you by email - (2006-10-25)
[936] Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21)
[1009] Passing GET parameters through Apache mod_rewrite - (2006-12-27)
[1114] PHP Image upload script - (2007-03-21)
[1183] Improving searches - from OR to AND? - (2007-05-11)
[1187] Updating a page strictly every minute (PHP, Perl) - (2007-05-14)
[1210] PHP header() function - uses and new restrictions - (2007-05-30)
[1355] .php or .html extension? Morally Static Pages - (2007-09-17)
[1379] Simple page password protection - PHP - (2007-10-04)
[1485] Copyright and theft of images, bandwidth and members. - (2007-12-26)
[1495] Single login and single threaded models - Java and PHP - (2008-01-04)
[1496] PHP / Web 2 logging - (2008-01-06)
[1505] Script to present commonly used images - PHP - (2008-01-13)
[1515] Keeping staff up to date on hotel room status - (2008-01-22)
[1518] Downloading data for use in Excel (from PHP / MySQL) - (2008-01-25)
[1549] http, https and ajp - comparison and choice - (2008-02-22)
[2632] Shipping a test harness with your class in PHP - (2010-02-12)
[2679] How to build a test harness into your PHP - (2010-03-16)
[2729] Uploading a document or image to its own URL via a browser - (2010-04-18)
[2918] Downloading a report from the web for further local analysis - (2010-08-13)
[3036] Sending out an email containing HTML from within a PHP page - (2010-11-07)
[3432] 3 digit HTTP status codes - what are they, which are most common, which should be a concern? - (2011-09-11)
[3540] Easy session example in PHP - keeping each customers data apart - (2011-12-06)
[3918] Multiple page web applications - maintaining state - PHP - (2012-11-10)
[4070] Passing variable between PHP pages - hidden fields, cookies and sessions - (2013-04-26)
[4483] Moving from mysql to mysqli - simple worked example - (2015-05-03)
A607 - Web Application Deployment - Apache httpd mod_rewrite [631] Apache httpd to Tomcat - jk v proxy - (2006-03-03)
[755] Using different URLs to navigate around a single script - (2006-06-11)
[934] Clustering, load balancing, mod_rewrite and mod_proxy - (2006-11-21)
[1006] Apache httpd and Apache Tomcat together tips - (2006-12-24)
[1207] Simple but effective use of mod_rewrite (Apache httpd) - (2007-05-27)
[1376] Choosing between mod_proxy and mod_rewrite - (2007-10-02)
[1381] Using a MySQL database to control mod_rewrite via PHP - (2007-10-06)
[1636] What to do if the Home Page is missing - (2008-05-08)
[1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
[1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
[1778] Pointing all the web pages in a directory at a database - (2008-08-30)
[1954] mod_rewrite for newcomers - (2008-12-20)
[2094] If you have a spelling mistake in your URL / page name - (2009-03-21)
[2555] Bookkeeping - (2009-12-29)
[2728] Redirecting a home page using mod_rewrite - (2010-04-17)
[2768] Carrying a long URL around - looking for memorable shorts - (2010-05-17)
[2773] Dynamically watching your web site via a PHP wrapper - (2010-05-21)
[2900] Redirecting a page - silent, temporary or permanent? - (2010-08-03)
[2981] How to set up short and meaningfull alternative URLs - (2010-10-02)
[3197] Finding and diverting image requests from rogue domains - (2011-03-08)
[3339] Simplest ever proxy configuration? - (2011-06-28)
[3753] Adding a passcode to a directory - (2012-06-05)
[3862] Forwarding a whole domain, except for a few directories - Apache http server - (2012-09-17)
A604 - Web Application Deployment - Apache httpd - virtual hosts [690] Adding Virtual Hosts - (2006-04-19)
[1687] Virtual Hosting on Apache httpd - a primer example - (2008-06-25)
[1896] Virtual Hosts and Virtual Servers - (2008-11-20)
[3132] Virtual Hosting with Apache http server - an overall scheme, and avoiding common pitfalls - (2011-01-14)
[4404] Which (virtual) host was visited? Tuning Apache log files, and Python analysis - (2015-01-23)
Some other Articles
Adding Expect on top of Tcl - what is it and where can I get a training course to learn about it?Comparing loop commands in TclTrapping errors in Tcl - the safety net that catch providesImages of the new year in MelkshamTelling which ServerAlias your visitor used - useful during merging domainsFirst of the yearInitial thoughts - response to GW Rail Franchise Consultation for WiltshireWhat would an appropriate train service on the TransWilts line meanI wish I was not a special caseHow big is a web page these days? Does the size of your pages matter?