zoukankan      html  css  js  c++  java
  • SEO中常用的301永久重定向代码大全

            301是永久重定向的意思,表示请求的网页已永久移动到新位置,服务器返回此响应(对 GET 或 HEAD 请求的响应)时,会自动将请求者转到新位置。其实301重定向在SEO中被广泛应用,也是被广泛认为比较好的重定向方法,301重定向可以归一权重、转移权重。小东北整理了一些这方面的资料,下面谈一些301在各个环境下的实现方法,网址以semshare.net为例。

    1、IIS下301设置

    Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择“资源的永久重定向”。

    2、ASP下的301转向代码

    <%@ %>
    <%
    Response.Status=”301 Moved Permanently”
    Response.AddHeader “Location”, “http://www.semshare.net/articles/301/”
    %>

    3、ASP.Net下的301转向代码

    <script runat=”server”>
    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Status = “301 Moved Permanently”;
    Response.AddHeader(”Location”,”http://www.semshare.net/articles/301/“);
    }
    </script>

    4、PHP下的301转向代码

    header(”HTTP/1.1 301 Moved Permanently”);
    header(”Location: http://www.semshare.net/articles/301/”);
    exit();

    5、CGI Perl下的301转向代码

    $q = new CGI;
    print $q->redirect(”http://www.new-url.com/”);

    6、JSP下的301转向代码

    <%
    response.setStatus(301);
    response.setHeader( “Location”, “http://www.semshare.net/” );
    response.setHeader( “Connection”, “close” );
    %>

    7、Apache下301转向代码

    新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

    1)将不带WWW的域名转向到带WWW的域名下

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^semshare.net [NC]
    RewriteRule ^(.*)$ http://www.semshare.net/$1 [L,R=301]

    2)重定向到新域名

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^(.*)$ http://www.semshare.net/$1 [L,R=301]

    3)使用正则进行301转向,实现伪静态

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^news-(.+).html$ news.php?id=$1

    将news.php?id=123这样的地址转向到news-123.html

    8、Apache下vhosts.conf中配置301转向

    为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:

    <VirtualHost *:80>
    ServerName www.semshare.net
    DocumentRoot /home/semshare
    </VirtualHost>

    <VirtualHost *:80>
    ServerName semshare.net
    RedirectMatch permanent ^/(.*) http://www.semshare.net/$1
    </VirtualHost>

    另外部分服务器IDC会提供自定义301等面板,根据具体实际情况来应用哈。

    测试一下你的跳转是否成功,提供2个301转向情况检测工具:

    http://www.seoconsultants.com/tools/headers.asp

    http://www.internetofficer.com/seo-tool/redirect-check/

  • 相关阅读:
    MySQL--lsblk命令查看块设备
    MySQL--linux IO调度算法
    一致性哈希
    MySQL--查询表统计信息
    MySQL--区分表名大小写
    MySQL--Online DDL
    MySQL--MODIFY COLUMN和ALTER COLUMN
    MySQL--修改表字段
    MySQL--增加或修改列注释
    鼠标事件
  • 原文地址:https://www.cnblogs.com/apolloren/p/9117618.html
Copyright © 2011-2022 走看看