是本文介绍web服务器301跳转方法,实现强制从www.liuyanzhao.com跳到liuyanzhao.com
一、空间的伪静态版本为ISAPI Rewrite 3.1,需要设置301重定向的,只用修改伪静态规则文件( .htaccess )即可。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.liuyanzhao.com [NC]
RewriteRule ^(.*)$ http://liuyanzhao.com/$1 [L,R=301]
将以上代码保存到文件名 .htaccess后上传到空间根目录即可。liuyanzhao.com 换成你自己的域名。
二、可用程序实现301重定义,只需修改程序即可。
1、如果是ASP程序,只需在index.asp首页的头部加下以下的绿色代码,liuyanzhao.com换成你自己的域名。
<%
if request.ServerVariables("HTTP_HOST")="www.liuyanzhao.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://liuyanzhao.com"
Response.End
end if
%>
2、如果是PHP程序,只需在index.php首页的头部加下以下的绿色代码,liuyanzhao.com换成你自己的域名。
<?php
if($_SERVER["HTTP_HOST"] == "www.liuyanzhao.com")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://liuyanzhao.com");
}
?>
3、如果ASP程序,但首页是html静态的实现301
<%
if request.ServerVariables("HTTP_HOST")="www.liuyanzhao.com" then
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://liuyanzhao.com"
Response.End
end if
%>
<!--#include file="index.html" -->
把上面代码保存为index.asp(如果文件名有存在可改为 301.asp等)上传到WEB目录下,并在管理平台的“修改默认首页”把index.asp(如改成其他文件名就要填其他文件名301.asp等)调到 最前面。(index.html为你首页的静态文件名)
4、如果PHP程序,但首页是html静态的实现301
<?php
if($_SERVER["HTTP_HOST"] == "www.liuyanzhao.com")
{
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://liuyanzhao.com");
}
?>
<?php include('index.html'); ?>
把上面代码保存为index.php(如果文件名有存在可改为301.php等)上传到WEB目录下,并在管 理平台的“修改默认首页”把index.php(如改成其他文件名就要填其他文件名301.php等)调到最前面。(index.html为你首页的静态 文件名)
原文地址:http://liuyanzhao.com/1665.html
5、如果你是asp.net 设置方法差不多相同,可以去百度搜索下”.net 301” 找相关教程。
6、如果你二级栏目或内容页也想实现301,也可以到百度搜索相关的程序教程。
7、http://tool.chinaz.com/pagestatus/ 此工具可以查看设置后有没有生效。
8.app.conf配置
handlers:
- url: /
script: /index.html
- redirect_host: www.liuyanzhao.com
status_code: 301
new_host: liuyanzhao.com
- rewrite_not_exist: (.*)
script: /index.php/$1