301重定向代码大全:iis 301重定向、apache 301重定向

很多做SEO的朋友找关于301重定向代码,下面我收集了一些关于php、aps、asp.net、Apache、cgi perl、jsp等的301重定向代码,希望对各位SEOer进行搜索引擎优化有帮助

1、PHP 301 重定向代码

header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: 
exit();

2、Apache301 重定向代码

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

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

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

2)重定向到新域名

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.mvpec.com/$1 [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、IIS下301设置

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

6、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/$1
</VirtualHost>

7、JSP 301重定向代码

<%
response.setStatus(301);
response.setHeader( “Location”, “http://www.mvpec.com/” );
response.setHeader( “Connection”, “close” );
%>

8、CGI Perl 301重定向代码

$q = new CGI;
print $q->redirect(”

Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档

301转向情况检测

http://www.seoconsultants.com/tools/headers.asphttp://www.internetofficer.com/seo-tool/redirect-check/

  Apache 301重定向代码我实践过,刚开始复制了代码进.htaccess不行,后面打开检查了一遍,原来复制代码没空行(本来就有.htaccess文件),一个回车-保存就搞定了!

作者: 樂思蜀
原载: 点石互动搜索引擎优化博客

出处:广州SEOWish博客[www.mvpec.com] 
转载请保留链接
本文链接地址:http://www.mvpec.com/wish/seo/25.html

原文地址:https://www.cnblogs.com/phyking/p/4456688.html