David Cramer's Blog

Python, Django, and Scale.

Redirect Non-WWW Requests to WWW

Since everything on page one of google isn’t, well, perfect, here’s a fully working example where you don’t need to type in your silly domain name.


# redirect all non-www traffic
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9\-]*)\.com$
RewriteRule ^.*$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

For the unknowing, this code uses mod_rewrite.

Comments