SEO, PHP and Javascript Web Dev

Search Engine Optimisation, Web Development and Network Administration Ramblings

-->
10  08 2006

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.

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 this Post:
  • Reddit
  • Sphinn
  • del.icio.us
  • Digg
  • e-mail
  • Mixx
  • Google
  • StumbleUpon

Related posts:

  1. Creating .htaccess on Windows
  2. 302 or to not 302, or to 301, or just nothing?
  3. Dynamic URLS
  4. Robots.txt
  5. Tip of the week : CakePHP deployment errors

No tags for this post.
« Duplicate Content
Robots.txt »

3 Responses to “301 Redirects”

  1. […] 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. […] Back to top Dynamic URLS301 RedirectsRobots.txtWhat is Google PageRank?Cloaking –> […]

  3. […] 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. […]

Leave a Reply

-->
  • Photography