R – Make apache automatically strip off the www.


For various reasons, such as cookies, SEO, and to keep things simple, I would like to make apache automatically redirect any requests for http://www.foobar.com/anything to http://foobar.com/anything. The best I could come up with is a mod_rewrite-based monstrosity, is there some easy simple way to tell it "Redirect all requests for domain ABC to XYZ"?

PS: I found this somewhat related question, but it's for IIS and does the opposite of what I want. Also it's still complex.

Best Solution

It's as easy as:

        ServerName www.example.com
        Redirect permanent / http://example.com/

Adapt host names and IPs as needed :)

Related Question