论坛
门户
内部优惠
喜欢
话题
VIP会员
搜索
新浪微博
登录
注册
100%
100%
首页
>
网络技术
>
网络技术
>
301重定向代码大全
回复
« 返回列表
灯火互联
管理员
注册日期
2011-07-27
发帖数
41778
QQ
火币
41290枚
粉丝
1086
关注
100
加关注
写私信
打招呼
阅读:
2681
回复:
0
301重定向代码大全
楼主
#
更多
只看楼主
倒序阅读
发布于:2011-10-02 11:32
保存
100%
100%
[]
1
1、PHP 301 重定向代码header(”HTTP/1.1 301 Moved Permanently”);
header(”Location:
http://www.mvpec.com/articles/301/
”);
exit();
2、Apache301 重定向代码新建。htaccess文件,输入下列内容(需要开启mod_rewrite):1)将不带WWW的域名转向到带WWW的域名下Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mvpec.com [NC]
RewriteRule ^(.*)$
http://www.mvpec.com/
[L,R=301]
2)重定向到新域名Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$
http://www.mvpec.com/
[L,R=301]
3)使用正则进行301转向,实现伪静态Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
将news.php?id=123这样的地址转向到news-123.html
3、ASP 301重定向代码<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “
http://www.mvpec.com/articles/301/
”
%>
4、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.mvpec.com/articles/301/
“);
}
</script>
5、Apache下vhosts.conf中配置301转向为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:<VirtualHost *:80>
ServerName
www.mvpec.com
DocumentRoot /home/mvpec
</VirtualHost>
<VirtualHost *:80>
ServerName lesishu.cn
RedirectMatch permanent ^/(.*)
http://www.mvpec.com/
</VirtualHost>
6、JSP 301重定向代码<%
response.setStatus(301);
response.setHeader( “Location”, “
http://www.mvpec.com/
” );
response.setHeader( “Connection”, “close” );
%>
7、CGI Perl 301重定向代码$q = new CGI;
print $q->redirect(”
http://www.new-url.com/
”);
8、nginx 301重定向代码把
www.hxj.com
和hxj.com合并,并把之前的域名也一并合并。 有两种实现方法,第一种方法是判断nginx核心变量host(老版本是http_host):
server {
server_name
www.hxj.com
hxj.com ;
if ($host != 'www.hxj.com' ) {
rewrite ^/(.*)$
http://www.hxj.com/
permanent;
}
…
}
第二种方法:
server {
server_name hxj.com;
rewrite ^/(.*)
http://www.hxj.com/
permanent;
}
这两种方法中, permanent是关键,详细说明见nginx重定向规则说明。
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301
301转向情况检测
http://www.seoconsultants.com/tools/headers.asp
http://www.internetofficer.com/seo-tool/redirect-check/
喜欢
0
评分
0
最新喜欢:
淘宝天猫隐藏优惠券地址
回复
100%
发帖
回复
« 返回列表
普通帖
您需要登录后才可以回帖,
登录
或者
注册
100%
返回顶部
关闭
最新喜欢