301 Redirects

So you've bought a new domain or you have changed/added some pages on your site? One of the most useful responses to provide a search engine bot is a 301 redirect - this tells the browser/bot that the page has permanently moved to this new location. What is a redirect? It is a header that gets to sent the browser/bot with a status code.

  • 100s - informational
  • 200s - successful
  • 300s - redirection
  • 400s - bad request
  • 500s - internal server error

Redirects are pretty easy, there are a number of ways to do it but here are a few simple ones...

Simple way

Easiest way is to set up a simple redirect in the .htaccess file for the site.

RedirectMatch 301 (.*) http://somenewsite.com/somepage.html

This will match anything at the domain/folder where the .htaccess file resides (you can have .htaccess files inside folders on your domain). The RedirectMatch means that you can use regular expressions.

Less Simple Way

Use mod_rewrite apache module. This module has to be compiled into apache - you can test this either by outputting phpinfo() and searching through it, or by testing mod_rewrite directly.

RewriteEngine on

RewriteBase /
RewriteRule ^(.*)$ http://somenewsite.com/$1 [R=301,L]

First line turns mod_rewrite on.

Second one sets the rewrite base to the root folder (not necessarily needed).

Third redirects essentially anything at the domain to somenewsite.com and sends a 301 status code back to the browser/spider.

There are a number of other ways to do this, but these are some of the easiest.