asp.net php jsp asp 301重新導向實現代碼

來源:互聯網
上載者:User

1.1 無www網域名稱轉移到www網域名稱
複製代碼 代碼如下:

rewriteengine on
rewritecond %{http_host} ^111cn.net [nc]
rewriterule ^(.*)$ http://www.111cn.net/$1 [r=301,nc]

1.2 整站301重新導向
複製代碼 代碼如下:

options +followsymlinks
rewriteengine on
rewritecond %{http_host} ^111cn.net [nc]
rewriterule ^(.*)$ http://www.111cn.net/$1 [l,r=301]
rewritecond %{http_host} ^www.111cn.net [nc]
rewriterule ^(.*)$ http://111cn.net/$1 [l,r=301]

另外一種是在根目錄下的index.php教程裡這樣弄
複製代碼 代碼如下:

header(“http/1.1 301 moved permanently”);
header(“location:http://111cn.net/”);
exit();

2、asp教程主機301重新導向
在 index.asp 或 default.asp 的最頂部加入以下幾行:
代碼如下:
複製代碼 代碼如下:

<%
response.status=”301 moved permanently”
response.addheader “location”,”www.111cn.net ”
response.end
%>

3、asp.net教程主機301重新導向
asp .net:

response.status = “301 moved permanently”;
response.addheader(”location”,"http://www.111cn.net");
}


我封裝在一個類裡:
複製代碼 代碼如下:

using system;
using system.collections.generic;
using system.text;
using system.web.ui;
using system.web.ui.htmlcontrols;
namespace classlib
{
public class urlclass
{
private bool flag301 = false;//是否啟動 301
private bool isindex = false;//是否 返回首頁 或者保留在當前頁
/// <summary>
/// 建構函式
/// </summary>
/// <param name="fl">是否啟動 301</param>
/// <param name="page">page</param>
/// <param name="strurl">格式www.xxx.com</param>
public urlclass(bool fl, page page, string strurl)
{
flag301 = fl;
url301(page, strurl);
}
/// <summary>
/// 返回首頁
/// </summary>
/// <param name="page"></param>
/// <param name="strurl">格式www.xxx.com</param>
public void url301(page page, string strurl)
{
//301重新導向
if (page.request.url.dnssafehost != strurl && flag301 == true)
{
page.response.clear();
page.response.statuscode = 301;
page.response.status = "301 movedpermanently";
page.response.addheader("location", "http://" + strurl);
page.response.end();
}
}
}
}

4 php的301重新導向
複製代碼 代碼如下:

header('http/1.1 301 moved permanently');//發出301頭部
header('location: http://www.'.$strdomain.$request_uri);//跳轉到我的新網域名稱地址

我用301.inc.php檔案寫了301代碼,在其他檔案頭部都引用上 就可以了
複製代碼 代碼如下:

<?php
//-----------------------------------
//301 重新導向
$strdomain="chinawecan.com";
$the_host = $_server['http_host']; //取得進入所輸入的網域名稱
$request_uri = isset($_server['request_uri']) ? $_server['request_uri'] : '';//判斷地址後面部分
if($the_host !== 'www.'.$strdomain) //這是我要以前的網域名稱
{
/*“!==”是不完全等於的意思,也可以用“!=”不等於,這樣,就可以將以前的網域名稱,
包括gcxirang.com、www.gcxirang.com以及新網域名稱中我gcidc.net全部重新導向到www.gcidc.net*/
header('http/1.1 301 moved permanently');//發出301頭部
header('location: http://www.'.$strdomain.$request_uri);//跳轉到我的新網域名稱地址
}
//----------------------------------
?>

引用如下:
複製代碼 代碼如下:

<?php
//-----------------------------------
//301 重新導向
include('include/301.inc.php');
?>

5 jsp教程的301重新導向
如一頁面article.jsp
[code]
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%>
<%
response.setstatus(https教程ervletresponse.sc_moved_permanently);
response.setheader("location","/other.jsp");
return;
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.