How does Stack Overflow (and other web sites) remove the \'www\' prefix when it\'s entered as part of a URL?
Is it a redirect, a rewrite or something else entirely?<
This is going a long way back, but as far as I know this is a DNS setup. I think you don't need to specify a HOST address (WWW is the name of the host (or computer/cluster...) that the site resides on/in.).
I think you can then set it up to send all requests to a default host.
Not 100% sure, but check out what is possible with DNS.
Hope that helps or at least get's you going in the right direction.
On Apache, it looks like this (inside an .htaccess file):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
For apache
<VirtualHost *:80>
ServerName yourdomain.tld
ServerAlias www.yourdomain.tld