301 Redirect

Posted on January 8, 2008 Categories: Search

post author

Written by: Jan

Jan is an eccentric Slovakian SEO wizard. When he's not researching search, optimising sites, building inbound links, or working on content creation, he's a part-time professor, teaching PHP to his students at university.

The 301 redirect is a method of informing both human visitors and search engines that an old URL has been moved. Basically, the 301 redirect indicates that the document was moved permanently. This redirect can be integrated into the PHP code, .htaccess file, ASP, etc.

Sponsored links

PHP 301 redirect

The following code must be placed before anything is generated as output. Actually, all headers must be sent from the server to the client before anything else. It is possible to work with databases to include other scripts and so on. The $new_url variable (see the code below) can contain any value (assuming it is a valid URL), so a link to internal page (http://example.com/page.php) is fine. Moreover, a new URL can be dynamic. Just avoid using & because it will not work properly. Instead, use & .

<?
$new_url = “http://www.domain.com/page.php?do=1&p=4″;
Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: $new_url” );
?>

.htaccess redirect

This kind of redirect can be a little tricky because if you want to redirect a particular page only, you should know regular expressions. For example, the following code will redirect everyone who typed http://your_domain.com/anything into the browser to http://www.your_domain.com/anything.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^your_domain.com [nc]
rewriterule ^(.*)$ http://www.your_domain.com/$1 [r=301,nc]

I personally recommend the PHP 301 redirect because it is possible to achieve the same goal without studying regular expressions. With the PHP functions substr, strpos, strlen and a few server’s parameters ($_SERVER), it is very simple.

When is the 301 redirect necessary?

If you just bought a website along with it’s content, or if you are updating old URLs of your website, you are likely to need a 3o1 redirect. For example, if the site is more than a month old, it’s possible that someone has bookmarked it or linked to it. All URLs without a proper redirect would instantly become broken URLs, and return a 404 error (page not found). Moreover, if your website receives organic traffic from search engines, all those visits will also end up with a 404 error.

As it’s already mentioned above, the 301 redirect means “moved permanently” which gives all the weight of the old URL to the new destination (the weight being age and incoming links). You probably already know that older documents rank better than new documents in Google. Without the 301 redirect all your progress so far would be lost. With the 301 redirect you avoid losing any position.

Types of redirect

In general there are a few common types of redirect. Meta, JavaScript and redirects based on headers (mentioned above). Although all redirects work the same way for a human visitor, they’re not equal in terms of SEO. The absence of the “moved permanently” aspect is very important, so it’s not recommended to use meta or JavaScript redirects when indicating that the web document was moved permanently. For instance, JavaScript redirects are suitable for advertising purposes. Meta redirects can be used for applications where the visitor wants to see updated data every 30 seconds, for example.

Follow us:

Leave a Reply

Archive

July 2010

June 2010

May 2010

April 2010

March 2010

February 2010

January 2010

December 2009

November 2009

May 2009

April 2009

March 2009

February 2009

January 2009

December 2008

November 2008

October 2008

September 2008

July 2008

June 2008

March 2008

February 2008

January 2008

December 2007

November 2007

October 2007

About Us

A team of nerds, creatives and strategy ninjas based in central London, building websites, social networks, widgets and social media apps.

We have a portfolio that is good enough to make a male peacock blush, and some killer outside-the-box products...in a box.
Ask us a Question

Blog posts