301转向代码合集
作者:乐思蜀 来源:点石互动 时间:2008-03-20 10:12:00
樂思蜀将SEO工作中所需要的301转向代码进行了整理,收藏并分享,以备查阅。
1、IIS下301设置
Internet信息服务管理器 -> 虚拟目录 -> 重定向到URL,输入需要转向的目标URL,并选择“资源的永久重定向”。
2、ASP下的301转向代码
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.lesishu.cn/articles/301/”
%>
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.lesishu.cn/articles/301/“);
}
</script>
4、PHP下的301转向代码
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.lesishu.cn/articles/301/”);
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.lesishu.cn/” );
response.setHeader( “Connection”, “close” );
%>
7、Apache下301转向代码
新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
1)将不带WWW的域名转向到带WWW的域名下
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^lesishu.cn [NC]
RewriteRule ^(.*)$ http://www.lesishu.cn/$1 [L,R=301]
2)重定向到新域名
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.lesishu.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.cn
DocumentRoot /home/lesishu
< irtualHost>
<VirtualHost *:80>
ServerName lesishu.cn
RedirectMatch permanent ^/(.*) http://www.lesishu.cn/$1
< irtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。
301转向情况检测
http://www.seoconsultants.com/tools/headers.asp
http://www.internetofficer.com/seo-tool/redirect-check/
标签:301,iis,代码,asp
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
网站数据库,是选SQL Server还是Access好
2008-05-23 13:19:00
用javascript做拖动层布局的思路
2008-05-30 13:38:00
使用SqlBulkCopy时应注意Sqlserver表中使用缺省值的列
2012-07-11 15:34:35
![](https://img.aspxhome.com/file/UploadPic/20127/11/2012711161735414.png)
"模板化"——限制还是激发
2009-03-26 11:36:00
Javascript 中截取小数位并实现四舍五入的方法
2008-08-05 18:11:00
JavaScript 图片变换效果(ie only)
2010-01-20 12:40:00
![](https://img.aspxhome.com/file/UploadPic/20101/20/2010120125735780s.gif)
5种禁用html页面的缓存方法
2007-09-30 12:12:00
javascript 45种缓动效果(一)
2009-09-19 18:30:00
成为一个顶级设计师的第一准则
2008-04-18 10:29:00
![](https://img.aspxhome.com/file/UploadPic/20084/18/2008418103351248s.jpg)
平面设计中的文字设计
2009-01-15 12:09:00
SaaS中的用户体验设计
2009-05-20 12:28:00
![](https://img.aspxhome.com/file/UploadPic/20095/20/p2009520103356-74s.jpg)
如何禁止搜索引擎收录你的网站
2008-10-20 12:57:00
谈谈网页设计中的字体应用 (2) serif 和 sans-serif
2009-11-24 13:04:00
![](https://img.aspxhome.com/file/UploadPic/200911/24/202939796-35s.gif)
JDBC连接MySQL数据库关键的四个步骤
2009-12-17 12:06:00
如何清除Vbscript惹出来的中文乱码?
2010-01-18 20:50:00
Flash对象在(x)HTML中的格式和参数及安全性
2010-04-01 11:55:00
![](https://img.aspxhome.com/file/UploadPic/20104/1/634042425122417500_1-54s.png)
使用MySQL数据库的23个注意事项
2010-03-18 15:46:00
ASP去掉字符串头尾连续回车和空格的Function
2011-04-03 11:13:00
Dreamweaver实现flash透明背景
2008-05-04 09:35:00
像懒人一样去设计
2009-04-23 12:43:00
![](https://img.aspxhome.com/file/UploadPic/20094/23/01-53s.jpg)