Pages

Tuesday 8 May 2012

11 Methods to implement 301 Redirect URLs

Need to 301 Redirect URLs:

1. Retains Search Engine Ranking: 301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It preserves your search engine rankings and indexing for that particular page.

2. Retains your visitors / traffic: If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.

Methods to 301 Redirect URLs:

1. HTML Redirect / Meta Refresh

Place the following HTML redirect code between the <HEAD> and </HEAD> tags of your HTML code.

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com">

The above HTML redirect code will redirect your visitors to another web page instantly. The content="0; may be changed to the number of seconds you want the browser to wait before redirecting.

2. PHP Redirect

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location:
http://www.new-url.com" );
?>


3. ASP Redirect

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


4. ASP .NET Redirect

<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>


5. JSP Redirect

<%
response.setStatus(301);
response.setHeader( "Location", "
http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>


6. CGI PERL Redirect

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

7. Ruby on Rails Redirect

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "
http://www.new-url.com/"
end


8. ColdFusion Redirect

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

9. Javascript URL Redirect

<head>
<script type="text/javascript">
window.location.href='http://www.newdomain.com/';
</script>
</head>


10. IIS Redirect

In internet services manager, right click on the file or folder you wish to redirect
Select the radio titled "a redirection to a URL".
Enter the redirection page
Check "The exact url entered above" and the "A permanent redirection for this resource"
Click on 'Apply'


11. Redirect to www using 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 website (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]

Note: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.