详解301重定向及实现方法
2012-07-06 09:09:57 来源:WEB开发网核心提示:# ISAPI_Rewrite 3.0 版本[ISAPI_Rewrite]# 3600 = 1 hourCacheClockRate 3600RepeatLimit 32RewriteCond %{HTTP:Host} ^www\.test10000\.com$RewriteRule (.*) http://www.1
# ISAPI_Rewrite 3.0 版本
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
RewriteCond %{HTTP:Host} ^www\.test10000\.com$
RewriteRule (.*) http://www.15597.com$1 [NC,R=301]
3. 将页面301重定向到另外一个页面
# ISAPI_Rewrite 2.x 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html$ /newpage.html[I,O,RP,L]
# ISAPI_Rewrite 3.0 版本 [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html$ /newpage.html[NC,L,R=301,O]
六、在网页后台程序中实现301重定向
如果页面是ASP/PHP/JSP/ASP.NET 可以再后台代码中做301重定向。
但是我个人不推荐这样,因为在服务器上做301跳转是在你的页面执行之前就开始跳转,效率高。而程序代码中做301,要为每个页面头部加转向代码,比较麻烦。
示例如下:
1、PHP下的301重定向
<?
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.15597.com");
?>
2、ASP下的301重定向
<%@ Language=VBScript %> <% Response.Status = "301 Moved Permanently" Response.AddHeader "Location", "http://www.15597.com" %>
3、ASP .NET下的301重定向
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader ("Location", "http://www.15597.com");
}
</script>
4、JSP下的301重定向
<%
response.setStatus(301);
response.setHeader("Location", "http://www.15597.com");
response.setHeader("Connection", "close");
%>
提示:如果返回报头中只有Location,但没有明确提到状态代码时,就意味着一个302临时重定向。请谨记于心。例如下面都是302重定向:
PHP 下的302重定向
<? php header("Location: http://www.15597.com"); ?>
Asp 下的302重定向
<% Response.Redirect "http://www.15597.com/" %>
ASP.NET 302重定向
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Redirect("http://www.15597.com");
}
</script>
JSP 下的302重定向
<%
response.sendRedirect("http://www.15597.com");
%>
总结:301重定向是一种对搜索引擎最友好的网址转向方法。在众多重定向技术中,301永久性重定向是最为安全的一种途径,也是极为理想的一款解决方案。无论是URL永久性改变,还是多种格式URL规范化都离不开301重定向。
更多精彩
赞助商链接
