国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

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

2024-07-21 02:02:37
字體:
供稿:網(wǎng)友

為什么需要使用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".
然后輸入目標(biāo)網(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 m.survivalescaperooms.com VeVb.com;
    if ($host = 'VeVb.com' ) {
        rewrite ^/(.*)$ http://m.survivalescaperooms.com/$1 permanent;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 英吉沙县| 五指山市| 政和县| 腾冲县| 沧州市| 灵台县| 武强县| 岑巩县| 交城县| 安岳县| 棋牌| 开原市| 大田县| 烟台市| 莱州市| 固安县| 弥渡县| 东山县| 贵德县| 吉安市| 嘉禾县| 睢宁县| 云南省| 竹溪县| 叶城县| 枣庄市| 临安市| 克拉玛依市| 禹城市| 施甸县| 东安县| 友谊县| 汪清县| 弥渡县| 康定县| 东山县| 湛江市| 湟中县| 于田县| 滦平县| 岗巴县|