It’s been said a million times, why do we need the www in the URL? The answer is simple: we want our sites to look professional. Here’s how to automatically prepend the www when some crazy hippie forgets it.

In the LoadModules section of the config, make sure mod_rewrite is enabled. On Red Hat or CentOS (or most others) it is by default:

In your LoadModules section, make sure that mod_rewrite is enabled. On Red Hat and CentOS, it is by default:

# grep mod_rewrite /etc/httpd/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so

In your VirtualHost container (or, to get fancy, in a .htaccess file), add the following lines:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Voíla. Bounce Apache, and visit. Make sure you’re cool enough not to type “www.”

/cs