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?<
An easy way to do this is using the Apache "Redirect" directive:
ServerName www.example.com
Redirect permanent / http://example.com/
ServerName example.com
# remainder of server configuration goes here
The Redirect directive automatically preserves anything following the / in the URL. I find this method easier to read and understand than the Rewrite method.