web服务器去掉域名www的301重定向设置方法

是本文介绍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

原文地址:http://liuyanzhao.com/1665.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半缘修道半缘君丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值