Removing the www sub domain from your url

For the most part, the www in a domain is pretty pointless. In general it's only there to make you type 4 extra characters to get to the site you want. It can also cause you a lot of pain trying to develop Ajax applications as I once found out.

There I was tying to get some Ajax working on a client site I was busy with only to be given some error about cross domain Ajax being disabled or not allowed. At first I figured I was sending Ajax requests from the development environment to the live site, but after some poking around in the code I saw that Ajax requests were going from to

This is not the only hassle the www sub domain can cause you, reporting and links can be off as well. There is also the matter of having url with www and without means you will be serving your assets more, as browsers will not use the cached css and JavaScript when visiting the different options. According to this site the best option is to redirect all traffic to Its a simple fix and requires adding two lines of code to your .htaccess file. For CakePHP you would want to do this in the APP/.htaccess file. It should end up looking something like the following:

This rule will only come into effect if the url starts with the www sub domain, and when its matched it will take all the params (if there are any) and redirect the user to the same place minus the www. You can try it out here, Check the url in your browsers navigation bar and you will see it does not have the www in it.

I personally hate getting to a site with a 404 or some other server error, only to find its missing the www in the url.

thinlineon 4/10/10

You should actually be doing the opposite. The reason is that can NOT have a CNAME record. It probably doesn't matter for small sites but you do limit yourself if you use

This is the same reason that and redirect to the www. equivalent of their domains.

Your logic for everything else is spot on though.