zoukankan      html  css  js  c++  java
  • 301重定向的方法

    第一种方法PHP:

    <?php
    
    $the_host = $_SERVER['HTTP_HOST'];//取得当前域名
    
    $the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断地址后面部分
    
    
    if($the_url=="/index.php")//判断是不是首页
    
    {
    
    $the_url="";//如果是首页,赋值为空
    
    }
    
    if($the_host !== 'www.xinlvtian.com')//如果域名不是带www的网址那么进行下面的301跳转
    
    {
    
    header('HTTP/1.1 301 Moved Permanently');//发出301头部
    
    header('Location:http://www.xinlvtian.com'.$the_url);//跳转到带www的网址
    
    }
    
    ?>

    第二种方法在网站根目录建立.htaccess文件:

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^www.xinlvtian.com$

    RewriteRule ^/?$ "http://blog.xinlvtian.com/" [R=301,L]

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^xinlvtian.com$

    RewriteRule ^/?$ "http://blog.xinlvtian.com/" [R=301,L]

    其中,www.xinlvtian.com,xinlvtian.com都重定向到blog.xinlvtian.com,大家只需要替换为自己的域名就可以了

  • 相关阅读:
    01-Django 简介
    函数及函数的嵌套等
    循环及循环嵌套
    运算符
    if, elif, else及if嵌套
    变量及变量计算和引用
    Python的3种执行方式
    Jmeter设置默认中文启动
    Vysor
    python基础学习(二)
  • 原文地址:https://www.cnblogs.com/xinlvtian/p/7932156.html
Copyright © 2011-2022 走看看