www vs no www

Note this only works on an Apache server with mod_rewrite turned on.
Google recommends using www or not www but not both. In other words, use www.mydomain.com or mydomain.com but not both. Using a 301 permanent redirect can alleviate the problem.
To redirect mydomain.com to www.mydomain.com do the following:

In an existing .htaccess file or a new .htaccess file add the following code:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

Replace mydomain with the domain you want to redirect. r=301 means redirect the client and send a status code of 301.

Doug

One Response to “www vs no www”

  1. Don’t Supplement the Supplemental Pages | Web Site Promotion Says:

    [...] other. Type in yourdomain.com and see if it redirects itself to http://www.yourdomain.com. Here is how to redirect non-www to www on an Apache [...]

Leave a Reply

You must be logged in to post a comment.