当前位置: 首页 > 图文教程 > 网站运营 > 建站经验 > 不同环境下网站进行301重定向的代码集锦

建站经验
好的互联网项目要具备三个核心要点
浅谈网站运营
沧海桑田 云卷云舒 赣县网依旧搜我的初恋
怎么让你的2.0社区显得更有价值?
边悦:我是如何干起Seo的
建站公司:企业建站如何从被动营销走向主动消费
邮政银行西联汇款单填写表格
风光一时,落魄一时。小垃圾站长的辛酸苦乐
小网站大流量就是这么来的!
出谋划策:浅谈WEB2.0时代的建站定位
三个月让你的网站PR值为5 搜狗PR=43
在Google搜不到我的网页
手把手教你结合seo制作一个新网站
他的博客为什么这样火?
如何通过在线广告来获取利润?
英文网站制作的几个关键注意事项
学习阿里巴巴商人论坛--市场运作分析
为什么说中文网站的域名应该尽量用拼音?
Ranking - 影响排名的六大因素
陶秋丰:浅议做网站的心态

建站经验 中的 不同环境下网站进行301重定向的代码集锦


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 167 ::
收藏到网摘: n/a

301重定向,也称为301转向。它的功能就是告诉搜索引擎,你的网址永久的变换了,从而将原网址的权重全部定向到新的网址上面,相信很多人都会用到301重定向的。

1、ASP下的301转向代码

<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://ruanchen.com/"#000000">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://ruanchen.com/"#000000">4、PHP下的301转向代码

header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://ruanchen.com/"#000000">5、CGI Perl下的301转向代码

$q = new CGI;
print $q->redirect(”http://ruanchen.com/"#000000">

6、JSP下的301转向代码

<%
response.setStatus(301);
response.setHeader( “Location”, “http://ruanchen.com/"#000000">7、Apache下301转向代码

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

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

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^lesishu.cn [NC]
RewriteRule ^(.*)$ http://ruanchen.com/"#000000">2)重定向到新域名

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://ruanchen.com/"#000000">3)使用正则进行301转向,实现伪静态

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

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