Help to set up a 301 permanent redirect using common techniques.
Online Advantage - Unleashing your websites potential Phone +64 7 376 9398
ARTICLES

GLOSSARY OF WEB TERMS


blogBLOG

View More >>
Share |




How do I set up a 301 Redirect?

301 redirects often come up in discussions with clients when they are doing some sort of redesign or upgrade where some of their webpages could change or move; or when our monthly Google Webmaster Tools checks report page errors such as 404 page not found errors.

A 301 redirect simply tells the search engines that a page has permanently moved from one location to another. The typical scenarios when a 301 redirect is required include:

  • When launching a new website on a new domain. This is sometimes due to rebranding where the old domain name needs to be redirected to a new one and you want to maximise the built up credibility of the existing domain and not have Google treat the new domain as a completely new site and drop it out of its current good positions.
  • When redesigning a website. Sometimes you may change the filenames and locations of certain pages or even remove them. It is important for the search engine spiders to be able to follow the redirect from the old outdated page to the new one so that they index the new website structure correctly and present the new or altered pages in search results.
  • When your website can be accessed by more than one URL, such as a www.yoursite.com, http://yoursite.com and yoursite.com. This is known as URL Canonicalisation and when a search engines canonicalises a URL it picks one to focus on. Using 301 redirects to point all other URLs to the correct one can ensure you present the correct information on your website and that your search marketing efforts are not diluted.

In addition 301 redirects can be required when:

  • You have pages that are regularly becoming outdated, such as real estate or accommodation listings.
  • You are removing pages on your site, such as deleting old staff profiles or product pages.
  • You are joining two websites together.

A 301 permanent redirect is recommended by Google and is seen as best practice around the world. Google provides instruction on 301 redirects in its webmaster support section and even has a video clip to watch:

http://www.google.com/support/webmasters/bin/answer.py?answer=93633

The two most common approaches are via Microsoft IIS and Apache Web Server. Please note that whilst we have provided code below it may not work for all hosting environments and we are not responsible for any errors or outcomes that occur. You should paste the code into a text editor first, such as Microsoft Notepad to clear any formatting.

301 permanent redirects with Microsoft IIS Web Server

In Microsoft IIS all necessary changes can be made directly through the Control Panel.

Administrator Mode

Administrator Mode is the best method to carry out redirects in a Windows environment for those who can log into the Windows 2000 (or higher) server and access the desktop. This is an example using the IIS 6.0 platform.

  1. Select Start / Setting / Control panel / Administrative Tools / Internet Information Services (IIS) Manager
  2. Click the cross beside the computer to drop down the list of configured folders within IIS.
  3. Now click to drop down the web sites folder which displays all the websites which are configured in IIS.
  4. Find the domain you want the 301 redirect for. Right click on it and select properties.
  5. On the tabbed menu above, click home directory. When in the home directory be very careful as you don’t want to accidentally alter any of the other settings as you could stop your website from being displayed.
  6. Select ‘A redirection to a URL’
  7. From the redirect website box type or paste in the website address you need the site to direct to. When this is done your website will forward but the process is not yet complete. You also need to click the permanent redirection option so that you notify the server that you want the redirection to be permanent.

301 permanent redirects with Apache Web Server

The Linux Operating system most commonly uses Apache web server. Various redirect methods can be used and we have listed a number of common ones below.

.htaccess Method

This is the best technique for those who have access to the web server and can create and upload an .htaccess file. This option is great as it provides the most control and also flexibility.

Apache .htaccess Single Page Redirect

Firstly create a file named .htaccess (no extension) then add the code below to the file using a text only editor and upload it to the root directory of your site:

RewriteEngine on

Redirect 301 /oldpage.html http://www.example.com/newpage.html

Apache .htaccess Canonical Redirect

As with before you will need to create a file named .htaccess and add the code below to the file using a text only editor and upload it to the root directory of your website. The code provided below will redirect all visitors accessing http://yoursite.com to http://www.yoursite.com:

RewriteEngine on

rewritecond %{http_host} ^domain.com [nc]

rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Control Panel Method

This is a good technique if you have administrator access to the cPanel. Note however that in some cases depending on the setup you might be limited with the types of redirects that you can do and a few control panels do not allow you to setup 301 redirects.

  1. Log into your cPanel, and find "Redirects" under Site Management
  2. Enter the current directory in the first box
  3. Enter the new directory in the second box
  4. Choose permanent=301
  5. Click "Add" and the task is completed.

On Page Redirects

On-page redirects can be a good idea when you only need to 301 redirect a couple of files, or where you don’t have adequate access to the web server (eg if using shared hosting), or if the server is not configured for an .htaccess file.  These guidelines apply to both Apache and Microsoft IIS.

PHP Single Page Redirect

To redirect a static page to a new address just enter the code below into the index.php file. Note that this code needs to be located in a script that is executed on the server before the page content starts:

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://www.newdomain.com/page.html");

exit();

?>

PHP Canonical Redirect

This code redirects all visitors accessing http://yoursite.com to http://www.yoursite.com. It must be located in a script that is executed in every page on the server before the page content starts:

if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {

header('HTTP/1.1 301 Moved Permanently');

header('Location: http://www.'.$_SERVER['HTTP_HOST']

.$_SERVER['REQUEST_URI']);

}

?>

ASP Single Page Redirect

This redirect method is used with the Active Server Pages platform. The code needs to be located in a script that is executed on the server before the page content starts:

<%

Response.Status="301 Moved Permanently"

Response.AddHeader='Location','http://www.new-url.com/'

%>

ASP Canonical Redirect

This code redirects all visitors accessing http://yoursite.com to http://www.yoursite.com. The code has to be located in a script that is executed in every page on the server before the page content starts:

<%

If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then

Response.Status="301 Moved Permanently"

Response.AddHeader "Location","http://www."

& Request.ServerVariables("HTTP_HOST")

& Request.ServerVariables("SCRIPT_NAME")

End if

%>


Posted on: 09 May 2011 at 7:25pm by Roy Bowers, modified on: 04 Apr 2012 at 5:06 pm
Post Comment




Categories
Client Login
Forgotten password? >
A few clients we have helped:
Free Ranking Report Free Ranking Report
Trade & EnterpriseOnline Advantage has been included on NZTE's E-Business guide as a 'recognised supplier of e-business services'