How do I create a 301 redirect?


301 Redirect methods

To redirect requests for one website to another, you can simply utilise the 'Forwarding' function of Plesk. However, for Search Engine Optimisation purposes, a '301 redirect' is often required. A 301 redirect indicates to the web browser accessing the website, that it has been moved permenantly to the new location.

There are several different ways of implementing this;

 

Redirect with .htaccess and Mod_Rewrite

The following code snippet is an example of utilizing the .htaccess file to handle domain and subdomain redirection. This method can be used to both temporarily, via 302 redirect method, as well as permanently redirect via 301 redirection. The .htaccess file is only used within Linux web server environments; however, the method will work 99% of the time regardless of whether you host your own servers or manage your web site hosting with a third-party vendor.


301 Redirect: xyz-site.com to www.xyz-site.com

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.xyz-site.com$ [NC]
RewriteRule ^(.*)$ http://www.xyz-site.com/$1 [L,R=301]


301 Redirect: www.xyz-site.com to xyz-site.com

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^xyz-site.com$ [NC]
RewriteRule ^(.*)$ http://xyz-site.com/$1 [L,R=301]


301 Redirect: Redirecting Individual pages

Redirect 301 /previous-page.html http://www.xyz-site.com/new-page.html

* These scripts should be placed in the .htaccess file.

 

Redirect with PHP

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.xyz-site.com" );
exit(0);
?>

* This script should be the first piece of code on the page to function correctly.

 

Redirect with classic ASP

<@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" Response.AddHeader "Location",
" http://www.xyz-site.com"
%>

* This script should be the first piece of code on the page to function correctly.

 

Redirect with ASP.NET

<script>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.xyz-site.com");
}
</script>

* This script should be the first piece of code on the page to function correctly.

 

Redirect with ColdFusion

<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://www.new-xyz-site.com/">

* This script should be the first piece of code on the page to function correctly.

 

Redirect with Perl

$q = new CGI;
print $q->redirect(" http://www.new-url.com/ ");

* This script should be the first piece of code on the page to function correctly.

 

 

Due to it's flexibility and ease of implementation, we recommend the PHP method for employing 301 redirect.

Last update:
2013-02-26 09:17
Author:
Nick Fawbert
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Most popular FAQs RSS

  1. I require an additional IPv4 address. What is Bytehouse's ... (87990 views)
  2. The Most Common Problems When Migrating Websites (66451 views)
  3. How do I create a 301 redirect? (55009 views)
  4. Can I Backup Exchange 2010 with My Online Backup ... (53176 views)
  5. Steps to Add Administrator User for Windows Server (48725 views)

Latest FAQs RSS

  1. Steps to set/customize log rotation from plesk (2016-07-25 07:15)
  2. Generate a self-signed SSL certificate - Nginx,CentOS (2016-07-07 02:31)
  3. Procedure re-register Volume Shadow Copy Service(VSS) in a Windows ... (2016-07-05 04:18)
  4. Steps to Install Mcrypt in Plesk (2016-07-01 17:11)
  5. How to Retrieve a Plesk Password in Linux and ... (2016-07-01 17:09)

Regular new KB articles

Check back from time to time for new articles, or if you have any suggestions please feel free to recommend

top