PHP ASP .NET Apache html python 網(wǎng)站301重定向
什么是301重定向?
301重定向(或叫301跳轉(zhuǎn))是當(dāng)用戶或搜索引擎向網(wǎng)站服務(wù)器發(fā)出瀏覽請求時,服務(wù)器返回的HTTP數(shù)據(jù)流中頭信息(header)中的狀態(tài)碼的一種,表示本網(wǎng)頁永久性轉(zhuǎn)移到另一個地址。
使用 301 重定向?qū)⒛瓉砭W(wǎng)站上的所有網(wǎng)頁永久重定向至新網(wǎng)站。這可以告訴搜索引擎和用戶您的網(wǎng)站已永久遷移。是符合搜索引擎友好的,目前最安全的網(wǎng)址域名更換。
以下提供URL重定向代碼,可以根據(jù)實(shí)際情況,進(jìn)行應(yīng)用
ASP.NET
<%@ Page Language=”C#” %>
<script runat=”server”>
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = “301 Moved Permanently”;
HttpContext.Current.Response.AddHeader(“Location”, http://fenghexin.com);
}
</script>
Apache
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://fenghexin.com$1 [R=301,L]
javascript
<script language=”javascript”>
top.location=’http://fenghexin.com’;
</script>
html
<meta http-equiv=”refresh” content=”0; url=http://fenghexin.com”>
asp
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://fenghexin.com”
Response.End
%>
php
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://fenghexin.com”);
exit();
?>
python
from django import http
def view(request):
return http.HttpResponseRedirect(‘http://fenghexin.com’)