really
April 14, 2005
Filed under: General — IO ERROR @ 10:10 am

To make all the traffic for http://example.com/ politely and silently redirect to http://www.example.com/ simply create a file called .htaccess (if it doesn’t already exist) and add the following to it, changing the red text to match your domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

These directions are for Apache and require that mod_rewrite be enabled. If you have any idea how to do this for IIS or any other web server, let me know and I will place the information here.

4 Comments »

  1. Hi!
    thanks for this tip!
    I was having some problems wit the Dean Edward’s IE7 script when visitors didnt access thru the “www” url.

    So I set thos rules for rewriting the URL and voila! problem fixed…

    Thanks again.

    Comment by Maniquí — February 16, 2006 @ 6:15 pm

  2. I tried putting the data you have above into an .htaccess file, but it didn’t do anything that I could see. Are there any specific AllowOverride options that you have to specify in the configuration file for it to work?

    Thanks!

    Comment by Nicholas — March 22, 2006 @ 6:44 pm

  3. I’m a die-hard anti-www guy, but I had to use your version for the site I’ve linked to, for some vague flash-related reason. The non-www version just wouldn’t work…
    Thanks.

    Comment by joseph — April 21, 2008 @ 6:08 am

  4. I’m making a site that will definitely benefit from an identifier for the “main” site, since people can sign up for their-user-name.mydomain.com, and your script works like a charm when it comes to disambiguation. Thanks!

    Comment by HB — June 12, 2008 @ 1:10 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Bad Behavior has blocked 72 access attempts in the last 7 days.