zoukankan      html  css  js  c++  java
  • 各种301转向代码

    一 IIS中实现301转向

    1.打开internet信息服务管理器,在欲重定向的网页或目录上按右键

    2.选中“重定向到URL”

    3.在对话框中输入目标页面的地址

    4.选中“资源的永久重定向”

    5.点击“应用”即可生效

    二 ASP下的301转向代码

       1. <%@ Language="VBScript" %>
       2. <%
       3. Response.Status = "301 Moved Permanently"
       4. Response.AddHeader "Location", "http //www url com"
       5. %>

    三 PHP下的301转向代码

       1. <?
       2. header("HTTP/1.1 301 Moved Permanently");
       3. header("Location http //www url com");
       4. exit();
       5. ?>

     四 ASP.Net下的301转向代码

       1. <script runat="server">
       2. private void Page_Load(object sender, System.EventArgs e)
       3. {
       4. Response.Status = "301 Moved Permanently";
       5. Response.AddHeader("Location","http //www url com");
       6. }
       7. </script>

    五 CGI Perl下的301转向代码

       1. $q = new CGI;
       2. print $q->redirect("http //www url com");

    七 Apache下301转向代码

    1)将不带WWW的域名转向到带WWW的域名下 
    
       1. Options +FollowSymLinks
       2. RewriteEngine on
       3. RewriteCond %{HTTP_HOST} ^url.com [NC]
       4. RewriteRule ^(.*)$ http //www url com/$1 [L,R=301]
    
       2)重定向到新域名 
    
        1. Options +FollowSymLinks
       2. RewriteEngine on
      3. RewriteRule ^(.*)$ http //www url com/$1 [L,R=301]

    八 Apache下vhosts.conf中配置301转向

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

    Apache下vhosts.conf中配置301转向

       1. <VirtualHost * 80>
       2. ServerName www url com
       3. DocumentRoot /home/lesishu
       4. </VirtualHost>
       5.
    
       6. <VirtualHost * 80>
       7. ServerName url.com
       8. RedirectMatch permanent ^/(.*) http //www url com/$1
       9. </VirtualHost>

    九 Ruby中实现301转向

       1. def old_action
       2. headers["Status"] = "301 Moved Permanently"
       3. redirect_to "http //www url com"
       4. end

    十 Coldfusion中实现301转向

    1. <.cfheader statuscode="301" statustext="Moved permanently">
    2. <.cfheader name="Location" value="http //www url com">
  • 相关阅读:
    升级centos6.5系统的gcc为4.8.5的简易步骤
    赛车比赛(洛谷U4566)
    月考(cogs 1176)
    xth的旅行(codevs 1450)
    魔法禁书目录2:回家(codevs 3024)
    交换
    牛的旅行(洛谷 1522)
    长途旅行
    序列问题
    正确答案
  • 原文地址:https://www.cnblogs.com/cdxkyz/p/2964565.html
Copyright © 2011-2022 走看看