Apache

ID #383

How can I make it clear to search engines that mydomain.com and www.mydomain.com are the same site?

Applies to: Grid System

Some search engine optimization (SEO) tests may advise you to make mydomain.com and www.mydomain.com appear as the same site to a search engine by using a permanent redirect. One way to do this is with Apache's mod_rewrite:

  1. Open a text editor (such as Windows' Notepad or Mac's TextEdit) and create a file named '.htaccess' that contains the following text:
    
       RewriteEngine on
       RewriteCond %{HTTP_HOST} www.mydomain.com$ [NC]
       RewriteRule ^(.*)$ http://mydomain.com/$1 [R=301,L]
    
  2. Upload the file to the /htdocs directory on mydomain.com. NOTE: Make sure that once it is uploaded the file is still called .htaccess. If it is not, rename it.

The rewrite rule above is equivalent to telling search engines, "Any requests for www.mydomain.com should be permanently redirected to http://mydomain.com," validating that they are in fact the same site.


Last update: 2010-10-05 16:15
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 5 (1 Vote)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Noah Masterson:
To do the reverse, from non-www to www:

RewriteEngine On
RewriteCond %{HTTP_HOST} example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Added at: 2010-10-14 19:04