Why you should or shouldn’t use www. infront of your domain name

I always thought this was a stupid topic that people would fight about. For a period of time I would make my sites not even care if its www.example.com or example.com. The short conclusion of this topic is simply this. Either work great, but you need to pick one or the other.

The big reason you find people telling you to do this is for Search Engine Optimization. Basically it just groups all of your web page results to one domain instead of breaking it between www.example.com and example.com. While they look the same to people, they are not == to a computer.

This is an argument that I never heard until I ran into this problem. This one is more important than the SEO one because I ran into a glitchy login system on my website. The more annoying part was that when I was vardumping the $_SESSION variable it would give results that didn’t equal the login page. After looking into the cookies on the computer I also realized that each user was creating 2 PHPSESSIONIDs. Basically doubling the load on my apache server. The cookie problem was that one cookie was for www.example.com and another was for example.com. You can get around this by always setting cookies on the .example.com domain but its hairy.

The least important one is for website branding to keep a consistent web address across the whole site. The fact of the matter is that even programmers don’t pay that close of attention.

How to fix this problem.
If you are on a shared hosting server you have to use mod-rewrite engine. I don’t like this approach, it makes every webpage have to be processes through a regular expressions. Talk about a waste. You may be able to do some fancy DNS work to redirect this but if you can get to the vhost files the better solution is to setup 2 vhosts.

vhost 1 : redirect to www. (or the reverse)
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/

vhost 2 : regular vhost definition

I'm a 32 year old UIUC Computer Engineer building mobile apps, websites and hardware integrations with an interest in 3D printing, biotechnology and Arduinos.

View Comments
There are currently no comments.