网站如何进行301转向

时间:2011-02-12 21:12:24

从网上收集整理的301域名重定向方法,希望对有这方面需要的网友一些帮助。

什么是301转向?

网址301重定向

 

1、IIS下301设置方法

Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择“资源的永久重定向”。

2、ASP下的301转向代码(放在ASP首页文件的文件头顶部上)

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.xxp520.cn/web/"
%>

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.xxp520.cn/web/");
}
</script>

4、PHP下的301转向代码

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.xxp520.cn/web/");
exit();

5、CGI Perl下的301转向代码

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

6、JSP下的301转向代码

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.xxp520.cn/" );
response.setHeader( "Connection", "close" );
%>

7、Apache下301转向代码

新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

1)将不带WWW的域名转向到带WWW的域名下

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxp520.cn [NC]
RewriteRule ^(.*)$ http://www.xxp520.cn/$1 [L,R=301]

2)重定向到新域名

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.xxp520.cn/$1 [L,R=301]

3)使用正则进行301转向,实现伪静态

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+).html$ news.php?id=$1

将news.php?id=123这样的地址转向到news-123.html

8、Apache下vhosts.conf中配置301转向

为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:

<VirtualHost *:80>
ServerName www.lesishu.com
DocumentRoot /home/lesishu
</VirtualHost>

<VirtualHost *:80>
ServerName lesishu.com
RedirectMatch permanent ^/(.*) http://www.xxp520.cn/$1
</VirtualHost>

301转向情况在线测试

http://tool.chinaz.com/pagestatus/

返回状态码为:301则说明转向成功。

例如:网页返回HEAD信息:

Location: http://xxp520.cn/web/

则说明网址已被转向到:http://xxp520.cn/web/
 

301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址。

其它常见的状态码还包括,200表示一切正常,404网页找不到,302暂时转向,等等。

本站所有文章均为天行博客原创,转载请注明来源及出处!

作者:宇天行 (关于我

本文首发地址:https://www.huceo.com/post/55.html

或许您还会喜欢这些文章:

Tags: 作者:宇天行 | 分类:开发技术 | 评论:0 | 浏览:4704

您正在以游客身份发表评论:

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。