- Home
- Web Related
- Redirect a page using a 301 redirect
Redirect a page using a 301 redirect
- By Tarik Sabbagh
- Published 8/11/2007
- Web Related
-
Rating:




Using a 301 redirect is the most efficient and Search Engine Friendly method of redirecting a web page.
A 301 redirect will help to preserve your page ranking, and is ideal for use when updating web page structures.
The code "301" is interpreted by the end user as "moved permanently" as opposed to a 302 redirect "Moved temporarily".
There are many ways to implement the page redirection.
PHP Redirect
Overwrite your PHP code, on the page you want the redirect to be initiated from with the below code (edited to your specs).
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com/new-page-name.php" );
?>
ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently";
Response.AddHeader("Location",http://www.new-url.com/);
%>
ASP .NET Redirect
Overwrite your ASP.NET code, on the page you want the redirect to be initiated from with the below code (edited to your specs).
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location",http://www.new-url.com);
}
</script>
ColdFusion Redirect
Overwrite your ColdFusion code, on the page you want the redirect to be initiated from with the below code (edited to your specs).
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value=http://www.new-url.com/>
JSP (Java) Redirect
Overwrite your JSP code, on the page you want the redirect to be initiated from with the below code (edited to your specs).
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>
CGI PERL Redirect
Overwrite your CGI code, on the page you want the redirect to be initiated from with the below code (edited to your specs).
$q = new CGI;
print $q->redirect("http://www.new-url.com/");
IIS Redirect
In Internet services manager, right click on the file or folder you wish to redirect
Select the radio button "a redirection to a URL".
Enter the redirection page
Check "The exact url entered above" and "A permanent redirection for this resource"
Click on 'Apply'
Redirect an Old domain to New domain (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old domain (i.e the same directory where your index file is placed)
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Please REPLACE www.newdomain.com in the above code with your actual domain name.
In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
Redirect to www (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old domain (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers using the Apache Mod-Rewrite module.
Spread The Word
1 Response to "Redirect a page using a 301 redirect" 
|
said this on 27 Nov 2007 7:06:06 AM EST
Very useful, I will use the PHP thingy from now on :) Gratzi!
|
Author/Admin)