zoukankan      html  css  js  c++  java
  • 服务器重定向与客户端重定向学习,辨析与实现

    1. 定义###

    网域名称转址(英语:URL redirection,或称网址重定向或URL重定向),是指当用户浏览某个网址时,将他导向到另一个网址的技术


    2. 作用###

    1. 相似域名

    2. 网站迁移至新域名

    3. 记录外送链接

    例:QQ邮箱中点击邮件链接是的警告其实服务器在收到邮件时就以做了处理
    
    1. 简化网址
    例:微博中的附加链接
    

    3. 分类###

    1. 服务器端跳转(forward跳转)
    1. 原理
    
      用户 *请求* -> 原服务器 *请求* -> 资源服务器 *响应* -> 用户
    
    2. 特点
    
      - 重定向后用户的URL没发生任何变化
    
      - 只能进行站点内跳转
    
      - 根目录代表服务器跟路径webapps
    
      - request设置的属性在跳转后的页面仍可以使用
    
      - 使用<jsp:param name="参数名" value="参数值" />传递参数
    
      - 执行到跳转语句后马上无条件跳转,之后的代码不再执行(跳转之前一定要释放全部资源)
    
    1. 客户端跳转(response跳转)
    1. 原理
    
      用户 *请求* -> 原服务器 *响应* -> 用户 *请求* -> 资源服务器 *响应* -> 用户
    
    2. 特点
    
      - URL变为重定向后所请求的URL
    
      - 可以进行站外跳转
    
      - 根目录代表站点根路径
    
      - 跳转后的页面不能使用上一个页面的request属性
    
      - 使用地址重写传递参数(response.sendRedirect("URL?参数名=参数值"))    
    
      - 所有代码执行完毕后跳转
    

    4. 实现###

    1. PHP
    
    <?php
    
    header('HTTP/1.1 301 Moved Permanently');
    
    header('Location: http://www.example.com/');
    
    exit();
    
    
    
    <?php
    
    header( 'Refresh: 0; url=http://www.example.com/' );
    
    exit();
    
    
    1. Apache HTTP Server's mod_alias extension
    
    Redirect permanent /oldpage.html http://www.example.com/newpage.html
    
    Redirect 301 /oldpage.html http://www.example.com/newpage.html
    
    
    1. Apache mod_rewrite
    
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^([^.:]+.)*oldsite.example.com.?(:[0-9]*)?$ [NC]
    
    RewriteRule ^(.*)$ http://newsite.example.net/$1 [R=301,L]
    
    
    1. HTML的Refresh Meta tag and HTTP refresh header
    
    <html>
    
        <head>
    
            <meta http-equiv="Refresh" content="0; url=http://www.example.com/" />
    
        </head>
    
        <body>
    
        </body>
    
    </html>
    
    
    1. HTML的Frame redirects
    
    <html>
    
        <frameset rows="100%">
    
          <frame src="http://www.example.com/">
    
        </frameset>
    
    </html>
    
    
    1. JavaScript redirects
    
    window.location='http://www.example.com/';
    
    

    感谢读者的来访,希望这篇博客能够帮到你,持续关注请使用RSS订阅或者关注我的账号:)

    本博客所有内容系作者原创,转载务必注明出处以对作者表示尊重!

    热爱互联网的 二两丶

  • 相关阅读:
    NYOJ 625 笨蛋的难题(二)
    NYOJ 102 次方求模
    ZJU Least Common Multiple
    ZJUOJ 1073 Round and Round We Go
    NYOJ 709 异形卵
    HDU 1279 验证角谷猜想
    BNUOJ 1015 信息战(一)——加密程序
    HDU 1202 The calculation of GPA
    "蓝桥杯“基础练习:字母图形
    "蓝桥杯“基础练习:数列特征
  • 原文地址:https://www.cnblogs.com/erliang/p/4065716.html
Copyright © 2011-2022 走看看