301转向代码

出自美国主机知识库

在2011年8月1日 (一) 09:03由Caojinxing927 (讨论 | 贡献)所做的修订版本
(差异) ←上一修订 | 最新修订 (差异) | 下一修订→ (差异)
跳转到: 导航, 搜索

<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.idcspy.org/newpage.html"); exit(); ?>

<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location", "http://www.idcspy.org" %>

下面代码保存为oldpagename.cfm <.cfheader statuscode="301" statustext="Moved permanently"> <.cfheader name="Location" value="http://www.idcspy.org/newpage.html">

private void Page_Load(object sender, System.EventArgs e) { Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.idcspy.org"); }

如果是Linux服务器,并且ApacheMod-Rewrite开启的时候,你可以在网站跟目录中创建.htaccess文件,通过.htaccess可以把所有收录为idcspy.org的链接修改为www.idcspy.org, .htaccess必须放在网站所在的目录中(即网站首页在同一个文件夹内),请把下面的代码写入.htaccess文件 RewriteEngine on rewritecond %{http_host} ^idcspy.org [nc] rewriterule ^(.*)$ http://www.idcspy.org/$1 [r=301,nc]

如果你的是Windows服务器,可以通过设置IIS实现301重定向 点击the Internet Services Manager,然后选择需要重定向的文件或文件夹 鼠标右键,选择 a redirection to a URL. 指定要重定向的文件名 选择 The exact URL entered above. 选择 A permanent redirection for this resource. 点击 Apply. 设置完成!

RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

个人工具
名字空间
变换
动作
导航
工具/资源
工具箱