URL HTTP Redirection

URL http redirection is an automatic URL change operation from one URL to another URL.

URL redirection

URL page redirection is an automatic URL change operation from one URL to another URL.

This redirection is done for the following reasons:

  1. Redirect from old obsolete URL to a new updated URL.
  2. Redirect from old obsolete domain to a new domain.
  3. Redirect from non www domain name to a www domain name.
  4. Redirect from short URL name to a long URL name - URL shortening service.
  5. URL shortening service will allow the user to insert a short URL and be redirected the the long URL that has the real page contents.

The user may reach the old URL from an old external links or a bookmark.

by the site's webmaster who adds a script.

Server side redirect

Server side redirection is done in the server, by configuring the Apache / IIS server software or by using PHP / ASP / ASP.NET script.

This is the preferred way to redirect URLs, since you can return HTTP 301 Moved Permanently status code.

Search engines use the 301 status to transfer the page rank from the old URL to the new URL.

Client side redirect

Client side redirection is done in the web browser of the user, by using HTML meta refresh tag or by Javascript code.

Client redirect is less preferred, since it does not return HTTP 301 status code.

Where to put redirect code

Domain
name
Hosting
server
Redirect code
placement
not changed not changed old page on same server
not changed changed old page on new server
changed not changed old page on same server
changed changed old page on old server

* Only with .htaccess redirect: add redirect code to httpd.conf file or to .htaccess file.

HTTP status codes

Status code Status code name Description
200 OK successful HTTP request
300 Multiple Choices  
301 Moved Permanently permanent URL redirection
302 Found temporary URL redirection
303 See Other  
304 Not Modified  
305 Use Proxy  
307 Temporary Redirect  
404 Not Found URL not found

HTTP 301 redirect

HTTP 301 Moved Permanently status code means a permanent URL redirection.

The 301 redirect is the preferred way to redirect URLs, since it informs search engines that the URL has moved for good, and search engines should put the new URL page in the search results instead of the old URL page and transfer the new URL page, the page rank of the old URL page.

The 301 redirect can be done across domains or on the same domain.

Google recommends to use 301 redirect.

Redirect options

Redirect script Redirect side Old page file type Redirect URL or domain Old URL server type 301 redirect support
PHP Server-side .php URL Apache / Linux yes
ASP Server-side .asp URL IIS / Windows yes
ASP.NET Server-side .aspx URL IIS / Windows yes
.htaccess Server-side all URL / Domain Apache / Linux yes
IIS Server-side all URL / Domain IIS / Windows yes
HTML canonical link tag Client-side .html URL all no
HTML meta refresh Client-side .html URL all no
HTML frame Client-side .html URL all no
Javascript Client-side .html URL all no
jQuery Client-side .html URL all no

redirect script - the scripting language that is used for the redirection.

redirect side - where the redirection takes place - server-side or client-side.

old page file type - the type of the old URL page that can can contain the scripting language of the redirect code.

redirect URL or domain - does support URL redirection of a single web page or domain redirection of a whole website.

typical old URL server type - the typical software and operating system of the server.

301 redirect support - indicates whether permanent 301 redirect status response can be returned.

PHP redirect

Replace old-page.php code with redirection code to new-page.php.

old_page.php:

<?php
// PHP permanent URL redirection
header("Location: http://www.mydomain.com/new-page.php", true, 301);
exit();
?>

The old page must have .php file extension.

The new page can be with any extension.

See: PHP redirect

Apache .htaccess redirect

.htaccess file is a local configuration file of the Apache server.

If you have permission the change the httpd.conf file, it is better to add the Redirect directive in thehttpd.conf instead of the .htaccess file.

Single URL redirect

Permanent redirect from old-page.html to new-page.html.

.htaccess:

Redirect 301 /old-page.html http://www.mydomain.com/new-page.html

Entire domain redirect

Permanent redirect from all domain pages to newdomain.com.

 .htaccess file should be at the old website's root directory.

.htaccess:

Redirect 301 / http://www.newdomain.com/

See: .htaccess redirection

ASP redirect

old-page.asp:

<%@ Language="VBScript" %>
<%
' ASP permanent URL redirection
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.mydomain.com/new-page.html"
Response.End
%>

ASP.NET redirect

old-page.aspx:

<script language="C#" runat="server">
// ASP.net permanent URL redirection
private void Page_Load(object sender, EventArgs e)
{
   Response.Status = "301 Moved Permanently";
   Response.AddHeader("Location","http://www.mydomain.com/new-page.html");
   Response.End();
}
</script>

HTML meta refresh redirect

HTML meta refresh tag redirection does not return 301 permanent redirect status code, but considered by Google as a 301 redirect.

Replace old page with redirection code with the URL of the page you want to redirect to.

old-page.html:

<!-- HTML meta refresh URL redirection -->
<html>
<head>
   <meta http-equiv="refresh" 
   content="0; url=http://www.mydomain.com/new-page.html">
</head>
<body>
   <p>The page has moved to:
   <a href="http://www.mydomain.com/new-page.html">this page</a></p>
</body>
</html>

See: HTML redirection

Javascript redirect

Javascript redirect does not return 301 permanent redirect status code.

Replace old page with redirection code with the URL of the page you want to redirect to.

old-page.html:

<html>
<body>
<script type="text/javascript">
    // Javascript URL redirection
    window.location.replace("http://www.mydomain.com/new-page.html");
</script>
</body>
</html>

See: Javascript redirection

jQuery redirect

jQuery redirect is actually another type of Javascript redirect.

jQuery redirect does not return 301 permanent redirect status code.

Replace old page with redirection code with the URL of the page you want to redirect to.

old-page.html:

<!DOCTYPE html>
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
   // jQuery URL redirection
   $(document).ready( function() {
      url = "http://www.mydomain.com/new-page.html";
      $( location ).attr("href", url);
  });
</script>
</body>
</html>

See: jQuery redirection

HTML canonical link tag redirect

The canonical link does not redirect to the preffred URL, but it can be an alternative to URL redirection for websites that most of the traffic arrives from search engines.

HTML canonical link tag can be used when there are several pages with similar content and you want to tell the search engines which page you preffer to use in the search results.

Canonical link tag can link to the same domain and also cross-domain.

Add the canonical link tag to the old page to link to the new page.

Add the canonical link tag to the pages that you preffer not to get search engines traffic to link to the preffered page.

The canonical link tag should be added in the <head> section.

old-page.html:

<link rel="canonical" href="http://www.mydomain.com/new-page.html">

See: Canonical URL link

HTML frame redirect

In frame redirection the new-page.html file is viewed by an html frame.

This is not a real URL redirection.

Frame redirection is not search engines friendly and is not recommended.

old-page.html:

<!-- HTML frame redirection -->
<html>
<head>
    <title>Title of new page</title>
</head>
<frameset cols="100%">
    <frame src="http://www.mydomain.com/new-page.html">
    <noframes>
     <a href="http://www.mydomain.com/new-page.html">Link to new page</a>
    </noframes>
</frameset>
</html>

javascript,HTML,PHP,ASP做301跳转代码 SEO优化设置的更多相关文章

  1. asp.net php asp jsp 301重定向的代码

    介绍一下针对各类程序系统实施301重定向的代码: 1.Linux主机重定向 Godaddy的Liunx主机,Godaddy本身已经支持Apache,所以直接创建一个.htaccess文件就可以了,一般 ...

  2. drupal 做301跳转(删除url里的www), 关键代码 可用到任何网站

    //hook_init(); function ex_init(){ //删除 url 前面的 www if (substr($_SERVER['HTTP_HOST'],0,3) == 'www'){ ...

  3. asp 301跳转代码

    <%    Response.Status="301 Moved Permanently"     Response.AddHeader "Location&quo ...

  4. iis6 服务器做301跳转返回状态码200解决方法。

    倘若你的配置和上图一样的话,在查询返回值是200的情况,你试着把你服务器上的安全狗或者防火墙,还有360网站卫士之类的安全软件停止试试,看是否能正常.

  5. 为什么要做外链建设?seo优化与发布外链速度有哪些联系?

    对于SEO员工来说,我们每天都在处理网页.从内容创建的角度来看,我们每天创建大量的URL并进入索引状态.与网站的受欢迎程度相比,网站每天也会生成大量的外部链接. 实际上,相对于链接而言,它满足了搜索引 ...

  6. phpcms9添加301跳转

    在做301跳转时遇到了"错误 310 (net::ERR_TOO_MANY_REDIRECTS):重定向过多."的问题,小编在这里把处理方法简单给大家写出来希望可以帮助到大家,另外 ...

  7. php实现301跳转

    php实现301跳转代码 <?php Header("HTTP/1.1 301 Moved Permanently"); Header("Location: htt ...

  8. asp.net mvc,做 301 永久重定向

    以下代码为 asp.net mvc 4.0 代码做的 301 永久重定向 string url = “http://www.csdn.net/test.html” Response.StatusCod ...

  9. 学习PHP 301跳转的方法

    发布:JB01   来源:脚本学堂     [大 中 小]本文详细介绍了,在php编程中实现301跳转,即301永久重定向的方法,感兴趣的朋友可以参考学习下. 本文转自:http://www.jbxu ...

随机推荐

  1. [codeforces 516]A. Drazil and Factorial

    [codeforces 516]A. Drazil and Factorial 试题描述 Drazil is playing a math game with Varda. Let's define  ...

  2. VS2010中如何查看DLL的导出接口

    看<VC++动态链接库(DLL)编程深入浅出>时,里面提到使用Visual C++的Depends工具可以查看动态链接库中的导出接口.对于VC6.0,VC所带的Depends软件,在VC6 ...

  3. [官方教程] [ES4封装教程]1.使用 VMware Player 创建适合封装的虚拟机

    [转载处,http://bbs.itiankong.com/] 前言: 首先要明确的一点,系统封装操作的源计算机一般为虚拟计算机(简称虚拟机.VM等),这也是为什么我们要在封装教程的第一章就专门学习虚 ...

  4. 最长公共子串 NYOJ 36

    http://acm.nyist.net/JudgeOnline/problem.php?pid=36 最长公共子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 ...

  5. Linux系统管理员面试50题

    命令nslookup是做什么的? Nslookup 是一个 监测网络中 DNS 服务器是否能正确实现域名解析的命令行工具. 你如何把CPU占用率最高的进程显示出来? top -c 按照cpu排序 如果 ...

  6. A PHP extension for Facebook's RocksDB

    A PHP extension for Facebook's RocksDB 31 commits 2 branches 0 releases 2 contributors C++ 90.5% C 8 ...

  7. linux 下如何查看和踢除正在登陆的其它用户 ==>Linux下用于查看系统当前登录用户信息的4种方法

    在linux系统中用pkill命令踢出在线登录用户 由于linux服务器允许多用户登录,公司很多人知道密码,工作造成一定的障碍 所以需要有时踢出指定的用户 1/#who   查出当前有那些终端登录(用 ...

  8. 36.在字符串中删除特定的字符[Delete source from dest]

    [题目] 输入两个字符串,从第一字符串中删除第二个字符串中所有的字符.例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”. ...

  9. 【JAVA、C++】LeetCode 021 Merge Two Sorted Lists

      Merge two sorted linked lists and return it as a new list. The new list should be made by splicing ...

  10. CSS对字体单位的总结

    国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的 ...