欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

12種實現(xiàn)301網(wǎng)頁重定向方法的代碼實例(含Web編程語言和Web服務(wù)器)

 更新時間:2014年07月10日 10:05:41   投稿:junjie  
這篇文章主要介紹了11種實現(xiàn)301網(wǎng)頁重定向方法的代碼實例,文中包含9種編程語言和3種WEB服務(wù)器配置方法,共計12種,需要的朋友可以參考下

為什么需要使用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 重定向代碼放在網(wǎng)頁的 <head> 節(jié)點內(nèi):
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com">
上述代碼立即將訪客重定向到另外一個頁面,你可以修改 content 中 的 0 這個值來表示幾秒鐘后才進行重定向。例如 content="3; url=http://www.oschina.net/" 表示三秒后再重定向。

2. PHP 重定向

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

3. ASP Redirect

復(fù)制代碼 代碼如下:

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

4. ASP .NET Redirect

復(fù)制代碼 代碼如下:

<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

復(fù)制代碼 代碼如下:

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

6. CGI PERL Redirect

復(fù)制代碼 代碼如下:

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

7. Ruby on Rails Redirect

復(fù)制代碼 代碼如下:

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

8. ColdFusion Redirect

復(fù)制代碼 代碼如下:

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

9. Javascript URL Redirect

復(fù)制代碼 代碼如下:

<head>
<script type="text/javascript">
window.location.;
</script>
</head>

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

11. 使用 .htaccess 進行重定向

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

復(fù)制代碼 代碼如下:
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

復(fù)制代碼 代碼如下:

server {
    server_name www.dbjr.com.cn jb51.net;
    if ($host = 'jb51.net' ) {
        rewrite ^/(.*)$ http://www.dbjr.com.cn/$1 permanent;
}

相關(guān)文章

最新評論