301重定向教程
精选
转载
301代表永久性转移(Permanently Moved),301重定向是网页更改地址后对搜索引擎友好的最好方法,罗嗦话我也不说了,既然你看了这篇文章,你应该是懂的301的具体意思了,下面就说说301转向代码的各种写法吧:
一: IIS中实现301转向:
1.打开internet信息服务管理器,在欲重定向的网页或目录上按右键
2.选中“重定向到URL”
3.在对话框中输入目标页面的地址
4.选中“资源的永久重定向”
5.点击“应用”即可生效
二:ASP下的301转向代码:
ASP下的301转向代码:
<%@ Language="VBScript" %>
<%
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.mf591.com"
%>
|
代码使用方法可参见本人以前写的关于301永久重定向的文章.
三:PHP下的301转向代码:
PHP下的301转向代码:
<?
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.mf591.com");
exit();
?>
|
四:ASP.Net下的301转向代码:
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.mf591.com");
}
</script>
|
五:CGI Perl下的301转向代码:
CGI Perl下的301转向代码:
$q = new CGI;
print $q->redirect("http://www.mf591.com");
|
六:JSP下的301转向代码:
JSP下的301转向代码:
<%
response.setStatus(301);
response.setHeader( "Location", "http://www.mf591.com" );
response.setHeader( "Connection", "close" );
%>
|
七:Apache下301转向代码:
新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
1)将不带WWW的域名转向到带WWW的域名下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^lesishu.cn [NC]
RewriteRule ^(.*)$ http://www.mf591.com/$1 [L,R=301]
|
2)重定向到新域名:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.mf591.com/$1 [L,R=301]
|
八:Apache下vhosts.conf中配置301转向:
为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:
Apache下vhosts.conf中配置301转向:
<VirtualHost *:80>
ServerName www.mf591.com
DocumentRoot /home/lesishu
</VirtualHost>
<VirtualHost *:80>
ServerName mf591.com
RedirectMatch permanent ^/(.*) http://www.mf591.com/$1
</VirtualHost>
|
九:Ruby中实现301转向:
Ruby中实现301转向:
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.mf591.com"
end
|
十:Coldfusion中实现301转向:
Coldfusion中实现301转向:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.mf591.com">
|
附:301转向情况检测地址
http://www.internetofficer.com/seo-tool/redirect-check/
输入你的url点:"Check Redirects"
若出现以下内容则301永久转向成功:
英文:
Response
Checked link: http://mf591.com
Type of redirect: 301 Moved Permanently
Redirected to: http://www.mf591.com
|
翻译成中文是:
中文:
检查链接: http://mf591.com
类型重定向: 301永久移动
重定向到: http://www.mf591.com
|
|