zoukankan      html  css  js  c++  java
  • 代码301完美解决虚拟空间永久重定向

    http://www.wocaoseo.com/thread-193-1-1.html 301对于seo来说有举足轻重的作用,大家可以参考《良好的收录始于301》;做301的方式有很多种,每一种方式都有他的独立性和约束性。然后代码301却能通用。

    代码301的原理很简单,假设现在有两个网页A和B我们要把A网页定向到B网页,当用户访问A网页的时候,服务器会解析一段301代码并返回B网页以及http状态。

    下面以asp程序为例子具体说明代码301的用法。

    第一步、建立index.asp页面放入下面代码(如果原来就存在可以移动到其他文件夹)

    ASP301代码:
    1. <% if left(request.ServerVariables(“HTTP_HOST”),4)<>”www.” then

    2. url = “http://www.”&request.ServerVariables(“HTTP_HOST”)
    3. if Request.ServerVariables(“QUERY_STRING”) <> “” then
    4. url = url & Request.ServerVariables(“SCRIPT_NAME”) & online casino game “?” & Request.ServerVariables(“QUERY_STRING”)
    5. end if
    6. Response.Status = “301 Moved Permanently”
    7. Response.AddHeader “Location”, url
    8. end if %>

    9. <!–#include file=”index.htm”–>
    复制代码


    第二步、网站默认启动首页为index.asp;

    第三步、调用原来的首页;

    下面给出php301代码:
    1. <?php if(substr($_SERVER["HTTP_HOST"],0,4)!=”www.”)
    2. {
    3. $url= “http://www.”.$_SERVER["HTTP_HOST"];
    4. if ($_SERVER["QUERY_STRING"]!=”") {
    5. $url = $url.$_SERVER["SCRIPT_NAME"] .”?”.$_SERVER["QUERY_STRING"];
    6. }
    7. header(“HTTP/1.1 301 Moved Permanently”);
    8. header(“location:$url”); } ?>

    9. <!–#include file=”index.html”–>
    复制代码
    代码301完美解决虚拟空间永久重定向



    以上内容由起源SEO论坛版权,订阅地址为http://www.wocaoseo.com/forum-2-1.html
  • 相关阅读:
    网络
    分区
    JavaScript概述
    CSS样式属性
    css选择器
    CSS的引入方式
    css介绍
    HTML结构
    常用标签
    HTML介绍
  • 原文地址:https://www.cnblogs.com/bjanzhuo/p/3629436.html
Copyright © 2011-2022 走看看