301 Redirects, Link Structure, XML Sitemaps, & Preferred Domain

Google representative Matt Cutts advises using 301 redirects to establish a preferred www or non-www domain. URLs such as www.example.com, example.com, www.example.com/index.html, and example.com/home.asp all seem like they point to the same page, but all of them, in fact, could contain unique content. In order to cut down on a search engine cataloging said content more than one time, and therefore diluting search engine results pages (SERPs), you can use 301 redirects, a good internal link structure, xml sitemaps, and set your preferred domain in your Google Webmaster Central account.

Using 301 Redirects

A popular variation on the Canonical Hostnames Example in Apache’s URL Rewriting Guide is to add the following to your root .htaccess file:

RewriteEngine on
# Redirect index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ http://www.example.com/$1 [R=301,L]
# Redirect www to non-www (or reverse if you prefer www)
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

One alternate method to use if you can’t get access to your .htaccess file is to use a php function like the one below. This would work great for a WordPress blog if you were to install it as the first line in your theme header.php file since it will be called for every page.

<?php
if ($_SERVER['HTTP_HOST']=='www.example.com' || $_SERVER['REQUEST_URI']=='/index.php') {
header("HTTP/1.1 301 Moved Permanently");
header('Location: ' . 'http://example.com/');
} ?>

Good Internal Link Structure

Make sure the links on your own site are consistent. If some of your links point to example.com and some point to www.example.com, there could be potential duplicate content issues. Pick the version you prefer and always use that format for your internal links.

XML Sitemaps

The sitemaps XML format is explained at sitemaps.org. In November 2006, Google, Yahoo, and Microsoft announced autodiscovery support for sitemaps via robots.txt. By April 2007, Google, Ask, Yahoo, and Microsoft had all confirmed support for XML sitemaps. For autodiscovery, add the following line to your robots.txt file:

Sitemap: <sitemap_location>

Of course, you should make sure the links used in your XML sitemaps are well-formed and correctly pointing to your preferred domain. Make sure to keep your sitemap file up to date. You can find more information about how the top search engines’ handle sitemaps including how to ping your sitemaps file or submit it manually using Google Webmaster Central and Yahoo Search Site Explorer.

Ping Addresses

  • http://www.google.com/webmasters/tools/ping?sitemap=
    http%3A%2F%2Fwww.yoursite.com%2Fsitemap.gz
  • http://ping.feeds.yahoo.com/rss/ping?u=[THE URL OF YOUR FEED]
  • http://submissions.ask.com/ping?sitemap=http%3A//www.the URL of your sitemap here.xml

Don’t forget about human readable site maps. Read Shari Thurow’s thoughts on the right way to think about site maps.

Set Your Preferred Domain in Google Webmaster Central

In addition to adding an XML sitemap, you can set your preferred domain in Google Webmaster Central.

🎲