Need to 301 Redirect URLs:
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.
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.
There's another way if usig IIS7, the simplest one:
ReplyDeletehttp://www.idea-r.it/Blog.aspx/asp-net-301-redirect
ReplyDeleteGreat Tutorial. The PHP code worked great but I am having some serious issues with the ASP code for another site. When applied to the default.asp page I get the following error, Microsoft VBScript compilation error ’800a0400′. So I removed the code so the site will work.
Any ideas will be greatly appreciated.
Hello Naresh Kumar,
ReplyDeleteI was looking for a simple 301 direct which I could implement in a html file.
I found your page and tried 9. Javascript URL Redirect:
I placed it in a htm file ... and it worked!
So, thanks for that powerful little piece of code!
I am very happy.
Do you have any experience with this method concerning Google ranking of those redirected html files? Is it a truly 301 method? Is Google maintaining ranking of the files that are redirected in this way? Do you know what I mean?
Is #9 better than:
?
Thanks in advance,
Gert Korthof
sorry, Naresh, the code of both examples is not shown. Well, let's forget about the second one and concentrate on the first one (#9 javascript).
ReplyDelete