• PHP 重定向


    <?php
    $the_host = $_SERVER['HTTP_HOST']; //取得当前域名
    $the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; //判断地址后面部分
    $the_url = strtolower($the_url); //将英文字母转成小写
    if ($the_url == "/index.php") //判断是不是首页
    {
    	$the_url = ""; //如果是首页,赋值为空
    }
    if (!in_array($the_host, array('www.example.com', 'example.com'))) //如果域名不是带www的网址那么进行下面的301跳转
    {
    	// header('HTTP/1.1 301 Moved Permanently'); //发出301头部
    	// header('Location:http://www.example.com' . $the_url); //跳转到带www的网址
    	// header("Location: http://www.example.com" . $the_url . $uri, TRUE, 301);
    	header("Content-type:text/html;Charset=utf-8");
    	exit('<script>' . 'location.href="http://www.example.com' . $the_url . '";</script>');
    }
    ?>
    
    -----------------------------------------------------
    说明:
      a).代码仅供学习交流
      b).本文根据自身经验及网络总结所作,如有错误,谢谢指教
      c).转载请注明出处。
    -----------------------------------------------------
  • 相关阅读:
    满血复活
    绝望,绝望、希望
    认真生活的态度
    星期一
    户外穿越
    认真准备
    早点休息
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
  • 原文地址:https://www.cnblogs.com/xqbumu/p/6839923.html
Copyright © 2020-2023  润新知