欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

歡迎來到云服務器

網絡技術

12種實現(xiàn)301網頁重定向方法的代碼實例

為什么需要使用301重定向:

1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不會影響到搜索引擎對頁面的排名。

2. 保留訪客和流量: 如果你將頁面鏈接到大量方法可以訪問過的地址,如果不是用重定向的話你就會失去這些用戶(不解)原文:If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.

下面是 11 中實現(xiàn) 301 重定向的方法:

1. HTML 重定向/Meta 刷新

將下面 HTML 重定向代碼放在網頁的 <head> 節(jié)點內:
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com"> 
上述代碼立即將訪客重定向到另外一個頁面,你可以修改 content 中 的 0 這個值來表示幾秒鐘后才進行重定向。例如 content="3; url=http://www.oschina.net/" 表示三秒后再重定向。

2. PHP 重定向

 

復制代碼代碼如下:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?> 

 

3. ASP Redirect

復制代碼代碼如下:

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>

 

4. ASP .NET Redirect

復制代碼代碼如下:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>

 

5. JSP Redirect

復制代碼代碼如下:

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>

 

6. CGI PERL Redirect

復制代碼代碼如下:

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

 

7. Ruby on Rails Redirect

復制代碼代碼如下:

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

 

8. ColdFusion Redirect

復制代碼代碼如下:

<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">

 

9. Javascript URL Redirect

復制代碼代碼如下:

<head>
<script type="text/javascript">
window.location.href='http://www.newdomain.com/';
</script>
</head>

 

10. IIS Redirect
在 Internet 服務管理器中右擊你想要重定向的文件和文件夾,選擇 "a redirection to a URL". 
然后輸入目標網址,選中 "The exact url entered above" 和 "A permanent redirection for this resource" 然后點擊 'Apply' 按鈕。

11. 使用 .htaccess 進行重定向

創(chuàng)建一個 .htaccess 文件(代碼如下)用來將訪問呢 domain.com 重定向到 www.domain.com 下,該文件必須放置在網站的root目錄,也就是首頁放置的目錄。

 

復制代碼代碼如下:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

 

注意: .htaccess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模塊啟用的情況下使用。

12.Nginx中的rewrite

 

復制代碼代碼如下:

server {
    server_name www.jb51.net jb51.net;
    if ($host = 'jb51.net' ) {
        rewrite ^/(.*)$ http://www.jb51.net/$1 permanent;
}
 
騰訊云代理

Copyright © 2003-2021 MFISP.COM. 國外vps服務器租用 夢飛云服務器租用 版權所有 ? 粵ICP備11019662號

主站蜘蛛池模板: 邢台市| 望江县| 临邑县| 武汉市| 读书| 体育| 芦山县| 米脂县| 平凉市| 化州市| 承德县| 麻城市| 泽普县| 新余市| 玉屏| 古田县| 家居| 穆棱市| 正安县| 湟中县| 额济纳旗| 乌恰县| 车致| 双江| 玛曲县| 时尚| 称多县| 玉树县| 阿合奇县| 九龙城区| 苗栗县| 张家界市| 巩义市| 明光市| 六盘水市| 长葛市| 鲁甸县| 永丰县| 永德县| 建平县| 三台县|