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

建站经验
建站经验:建设网站该学的一些知识
内容类网站提高网站粘度的常见方法
网络推广软文写法经验心得
邀请的页面设计和邀请邮件的设计
网站制作推广过程中注意的11点内容
交换友情链接和做外链的问题
怎么做淘宝客,如何做淘宝客
建站经验:你的网站该如何应对被采集
小说类网站文字排版技巧
打造高流量博客网站的四种方法
互联网改变中国服装行业的销售方式
建立博客:目前最流行的10款国外博客程序
网页设计中提高可读性的方法
网站被搜索引擎降权的处理方法
你听说过月赚4万美圆的个人博客吗?
网络推广充分利用百度知道
友情链接和运营网站的关系
博客赚钱经验:想通过博客赚钱
什么样的博客才能称之为成功?
建站经验分享:做网站的思路

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 122 ::
收藏到网摘: 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