Onetomarket

This article is based on the excellent overview of Steven Hargrove.

Each website is – to a greater or lesser extent – updated, changed and there are even entire pages or domains removed.
Now that your website has been renovated completely. The file names are changed (for example index.html to index.php), etc.
Of course this is fantastic: a Web site must be improved continuously! But what if you want to get rid of the old pages without being concerned about people who stream old links to the old pages and then land on a ’404 not found ‘error? That’s not all, search engines like Google and Yahoo and MSN may have the old urls in their index and send visitors to the now deleted pages …

The 301 redirect

The best way to redirect those pages is to redirect with the so-called ’301 ‘. What does this 301 redirect do, The redirect automatically forwards to a new page when it is called. This makes the 301 redirect the best, not only because it automatically forwards (which the ’302 redirect also does), but it also does it safely, without that you have to fear for penalties from the search engines.
Specifically spoken the 301 redirect tells the browser or search engine that the page is moved and sends the client (browser or search engine) automatically to the new address. It tells them, in spoken word: ‘Hey, this page was moved here and this is the new address! “.
For you as the reader, the technique will be far more important, so we go further with the technique now.

There are several ways to use a 301 redirect: PHP, ASP, ASP.NET, JSP (JAVA), IIS, ColdFusion, CGI/PERL and finally with Htaccess. The most powerful technique is to use the so-called Apache mod_rewrite module in httpd.conf or .htaccess.

Redirect with HTML or Javascript

You want to know how you can use HTML or Javascript to redirect?! Very simple: Don’t!
In the past, the so-called “meta-tag refresh redirection method is often abused with the aim to spamming. The result is that the use of it is penalized by the search engines. So don’t use it.

301 redirect with .htaccess

The big advantage of using .htaccess is the fact that redirects can be regulated on a meta-level. Unlike with the mentioned programming languages .htaccess can redirect an entire directory.
It works as follows:
1. Create a file named “.htaccess” (note the dot in the beginning!) and place it in the root of the website;
2. Open the .htaccess file in a code-editor and add the following lines to the .htaccess file:
Redirect 301 /old/old.html http://www.yoursite.com/new.html
Please note: the first part of the statement concerns the path of the old files FROM the top level of the site (So without the ‘http://www’). Also note that there is a space between these elements:
redirect 301 (The instruction that the page has been moved permanently)
/old/old.html (The old relative path en name)
http://www.you.com/new.html (new complete path and name)
Also notice that it is not required for pages to redirect to a new domain name. This can be done within a domain too!

301 redirect with Mod_Rewrite

There is much more possible within the world of redirecting with mod_rewrite, a module of the Apache Web server.
This is an incredibly powerful module where regular expressions are used, for example, to flare dynamically redirects. I show an useful example below.
When someone links to your site, they don’t always exactly use the way you prefer.
If someone links to http://www.yoursite.com and someone else links to http://yoursite.com, then Google will use a separate page rank for each url.

Yes, that’s clumsy, but it’s a fact. You can customize it with the code below.
Incidentally, those who use sitemaps in Google webmaster central, can indicate under the “preferred domain” submenu, whether they prefer Google to index the www-variant or the www-free version of their Web site.
RewriteEngine On
rewritecond %{http_host} ^yoursite.com
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]

301 redirect with IIS

1. Use the right mouse button in the Internet Services Manager to choose which folder should be redirected;
2. select the radio button that says “a redirection to a URL ‘;
3. fill in the page where to will be directed;
4. Check “The exact URL entered above” and “A permanent redirection for this resource”;
5. Click on ‘Apply’.

301 redirect with Cold Fusion

For most server-side scripting and programming languages is the use of 301-redirect quite simple.

In Cold Fusion it works as follows:


301 redirect with PHP

Use the following code:
<?php
header( "Status: 301 Moved Permanently" );
header( "Location: http://www.yoursite.com/" );
exit(0); // this is optional, but is recommended. This will help prevent unnecessary output?>
ps: The Microsoft IIS server crashes if you use the following (more common) used line:
header( "HTTP/1.1 301 Moved Permanently" ); ?>


301 redirect with ASP

Use the following code:
< %@ Language=VBScript %>
< %
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.yoursite.com /"
%>

301 redirect with ASP.NET

Use the following code:
>

301 redirect with JSP / JAVA

Use the following code:
< %
response.setStatus(301);
response.setHeader( "Location", "http://www.yoursite.com /" );
response.setHeader( "Connection", "close" );
%>
301 redirect with CGI / PERL
Use the following code:
$q = new CGI;
print $q->redirect(" http://www.yoursite.com / ");
301 redirect with Ruby / Ruby on Rails
Use the following code:
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.yoursite.com/"
end

Disclaimer: we have used these techniques in practice and found out that the operation is quit satisfying. But there are 567897653 ways in which it can go wrong. Therefore the use of these techniques is at your own risk!

Joost Brok

Over Joost Brok

Joost Brok is working part-time at Onetomarket as an SEO/link builder. His interests lie mainly by search engine optimization, social media, usability and brainstorming. Besides his job at Onetomarket he is studying Business Engineering.
meer reacties Plaats uw reactie!

Gerelateerde artikelen

2 reacties to “301 Redirects: an overview”

Reageer!

Naam (verplicht)
E-mail (wordt niet getoond) (verplicht)
Website


Subscribe by e-mail

We won’t share your address with others, we will keep you informed about everything that is in your company’s best interest.

Related articles

Related services

Get in touch with us






Knowledgebase

7 reasons why link building needs patience

Lets just paraphrase this article; link building costs time. Lots of time. Because a lot of people want immediate results I will focus a lot of time and energy on this post to clarify why it is important to have loads of patience. To name a few: it takes time to become an authority it [...]
more information

Linkbait: what it is, tips & tricks

An compelling explanation of a phenomenon that is called linkbait, how it works, how you can recognize it and what it can do for your business.
more information

Preventing 404s in 7 steps

In this article I will explain you as a webmaster or marketer how you could prevent these messages on the basis of a simple roadmap.
more information

Take me to the: knowlegdebase

Why work with us?

Meet with over 10 years of online marketing experience:
- Integrated approach to interactive marketing
- Appealing clients and references
- Internationally operating
- Working on long and successful relationships
- Speaker for major conferences and guest lectures
- Accreditations Google, Yahoo, Omniture and Microsoft
- Author SEO Book and Handbook Conversion Optimization

Get in contact with one of our