THANKS FOR GETTING IN TOUCH

We aim to respond to all messages within 1 business day. You'll be hearing from us soon!

In the meantime, perhaps you'd like to learn more...

EXCITING!

We'd love to help you get your next digital project off the ground.

HOW CAN WE REACH YOU?

*Required Fields
*
*
*
*

HOW CAN WE HELP YOU BE SMARTER ONLINE

*
Your personal information will only be used to service your enquiry.
We will only contact you with relevant information. For further information view our full Privacy Policy.
CLOSE
 

How to setup a 301 Permanent Redirect

October 15, 2008

In our previous post SEO Considerations When Redesigning a Website we touched on how to mitigate the ill effects of changing your website domain or file names by using 301 Permanent Redirects. Here we will give you instruction on how to set up this redirect on both Apache and Microsoft IIS web servers.

The “301 Permanent Redirect” is the most efficient and search engine friendly method for redirecting websites. Situations include:

  • To redirect an old domain name to a new domain name – normally in the case of re-branding
  • When you have several domain names pointing to one website but are only wishing to promote one domain name
  • When access to your website is possible via multiple URLs such as http://domain.com/ or http://www.domain.com. It is preferable to select one and 301 redirect the others to the one you have chosen. This is referred to as Canonicalisation.
  • Merging two websites together and want links to outdated URLs to be seamlessly redirected to the corresponding page on the new site.

Here is Google’s webmaster guideline on 301 redirects: http://www.google.com/support/webmasters/bin/answer.py?answer=93633

Apache Web Server

The Linux Operating system most commonly uses Apache web server. There are a number of methods of redirect available:

.htaccess Method

If you have sufficient access to the web server then the very best method of redirection is the creation and upload of an .htaccess file as this gives you the most flexibility and control:

Apache .htaccess Single Page Redirect
You will need to create a file named .htaccess (no extension), add the code below to the file using a text only editor and upload it to the root directory of your website:

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

Apache .htaccess Canonical Redirect
Again you will need to create a file named .htaccess, add the code below to
the file using a text only editor and upload it to the root directory of your website. The code below will redirect all visitors accessing http://domain.com to http://www.domain.com:

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

Control Panel Method

If you have Administrator access to the cPanel then this is another method of redirection but you may find that you are limited with the types of redirects that you can do, for example the Plesk control panel does not allow for 301 redirects.

cPanel redirect

Log into your cPanel, and look for "Redirects" under Site Management
Put in the current directory into the first box
Put the new directory in the second box
Choose the type (temporary or permanent) temporary=302 and permanent=301
Click "Add" and you're done

On Page Redirects

In instances where you are only wishing to redirect one or two files and perhaps don’t have the server correctly configured for an .htaccess file or where you do not have sufficient access to the web server such as in a shared hosting environment, you can use on-page redirects.

Read more info on both PHP and ASP redirects.

Microsoft IIS Web Server

IIS supports the requirement for 301 redirection and all necessary changes can be made directly through the Control Panel. 

Administrator Mode

If you can log into the Windows 2000 (or higher) server and access the desktop, then this is the best method to carry out redirects in a Windows environment. The example below is based on the IIS 6.0 platform.

  • Choose Start / Setting / Control panel / Administrative Tools / Internet Information Services (IIS) Manager
  • Click the cross that is next to the computer to drop down the list of the configured folders within IIS.
  • Next you need to drop down the web sites folder; this will display all the website that have been configured in IIS.
  • Locate the domain that you wish to setup the 301 redirect on. When you have located this domain right click on it and select properties.
  • On the tabbed menu above click home directory. Once you are in the home directory pay close attention, you do not want to mess with any other settings this could result in your website not being displayed.
  • Select ‘A redirection to a URL’
  • In the redirect website box: Enter the website address that you want the site to direct to. Once you have done this, your website will forward but it still has not been set correctly, you must click a permanent redirection to; by checking this button you are telling the server that you want the redirection to be permanent.

On Page Redirects – See Below

On Page Redirects – More Information

PHP Single Page Redirect
In order to redirect a static page to a new address simply enter the code below inside the index.php file. This code must 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
The code below will redirect all visitors accessing http://domain.com to http://www.domain.com. This code 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. This code must 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
The code below will redirect all visitors accessing http://domain.com to http://www.domain.com. This code must 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","<a href="http://www/">http://www</a>."
& Request.ServerVariables("HTTP_HOST")
& Request.ServerVariables("SCRIPT_NAME")
End if
%>

These are some of the methods available to ensure you preserve your Internet footprint when updating your site content.

Disclaimer
All care has been taken in preparing the code in this blog, however no guarantee is offered as to the suitability of this code for your particular hosting environment. We suggest you copy the code into a text editor to remove all formatting. No responsibility is accepted for errors or omissions.

^ top
Filed under Design & Development

Written by

Here from the very beginning, Karyn was originally a co-founder of Apex Digital and carried the Strategy & Marketing Director title for more than two decades. Karyn switched gears at the end of 2018 when she returned to study in a new field. Now in a contract Content Writer capacity, she has a wealth of knowledge in the industry and has been...

Related posts

Leave a comment

Fields marked * are required

ARE YOU READY TO BE SMARTER ONLINE TOO?WANT TO GET STARTED?
HERE'S HOW
YES

AWESOME! LET'S GET STARTED

TELL US HOW WE CAN HELP

THANKS FOR GETTING IN TOUCH

We aim to respond to all messages within 1 business day. You'll be hearing from us soon!

In the meantime, perhaps you'd like to learn more...

Our friendly team can be reached Monday - Friday from 8.30am to 5.00pm.
Fill in your details below and we'll get back to you lightning fast.

* *
* *
*
*
*
*Required Fields
Your personal information will only be used to service your enquiry.
We will only contact you with relevant information. For further information view our full Privacy Policy.