Skip to content


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.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • E-mail this story to a friend!
  • Fark
  • Reddit
  • StumbleUpon

Profile:  Frank has been programming for the web using PHP, Javascript and numerous libraries and frameworks for the past 5 years. More articles.

Posted in SEO.

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Continuing the Discussion

  1. franktank.com » Robots.txt linked to this post on August 11, 2006

    [...] Why is it good to have a robots.txt file? Well if you do not have any areas on your site that you want to exclude from search engine indexes then it isn’t necessary to have a robots.txt file at all. However, when a bot comes to your site and requests a robots.txt file it will get a 404 error (header response)  in return - this error will pop up in your logs so if you don’t want to clutter your logs and return errors then just create an empty robots.txt file. [...]

  2. franktank.com : Blog Archive » Useful Google Tools linked to this post on October 11, 2006

    [...] Back to top Dynamic URLS301 RedirectsRobots.txtWhat is Google PageRank?Cloaking –> [...]

  3. franktank.com : Blog Archive » 302 or to not 302, or to 301, or just nothing? linked to this post on January 17, 2007

    [...] The debate is all about what response header to return to the browser/spider when you have moved a page on your site to another location. The 301 or 302 bit is the status code (more info on status codes and redirects). It is important because a browser/spider will interpret the status code and act accordingly. What you want both visitors and spiders to know is that the page has not disappeared, but it is simply over here on this other part of the web - for the obvious reasons that if someone is looking for it they can find the content they were after. [...]

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.