教你如何做301 重定向
教你如何做301 重定向301 转向代码的各种写法来源:商渡网(www.33w.net.cn )301 代表永久性转移(Permanently Moved),301 重定向是网页更改地址后对搜索引擎友
教你如何做301 重定向
301 转向代码的各种写法
来源:商渡网(www.33w.net.cn )
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转向代码:
private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.mf591.com"); }
,五: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转向:
ServerName www.mf591.com DocumentRoot /home/lesishu
ServerName mf591.com
RedirectMatch permanent ^/(.*) http://www.mf591.com/$1
,九: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转向情况检测地址
若出现以下内容则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