顶级域名怎么替换index.html,如何将顶级域名做301重定向

为什么要对顶级域名做301重定向?

这样做有利于SEO,原因是我们常常会碰到这样的情况,其他网站链接你的站点时,可能会用下面的链接:

www.maixj.net

maixj.net

www.maixj.net/index.php

maixj.net/index.php

而你的网站最好只能有一个主入口:www.maixj.net,需要将其它样式的链接都重定向到主入口,汇聚网站权重。

如何实现?

wordpress网站不需要做顶级域名301重定向。wordpress网站在配置了固定链接之后,会自动在网站根目录生成.htaccess,这个文件已经包含了301重定向的功能。

Apache服务器可通过修改配置来实现301重定向

1, 修改httpd.conf文件,确保ReWrite模块开启,并在相应目录支持ReWrite功能:

#将下面这一行的#号去掉

LoadModule rewrite_module modules/mod_rewrite.so

#网站目录下的Allowoverride设置

DocumentRoot "C:/maixj.net/..../site"

#

# Possible values for the Options directive are "None", "All",

# or any combination of:

# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important. Please see

# http://httpd.apache.org/docs/2.4/mod/core.html#options

# for more information.

#

Options FollowSymLinks Includes ExecCGI

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

# AllowOverride FileInfo AuthConfig Limit

#

AllowOverride all

2, 设置.htaccess文件(一般虚拟主机都支持自己设置.htaccess文件)

使访问maixj.com的时候就会自动转到www.maixj.com

在网站根目录的.htaccess文件里写上以下代码即可:

RewriteEngine on

RewriteCond %{http_host} ^yourdomain.com [NC]

RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

这段代码的意识就是通正则表达式,将直接访问顶级域名的请求,全部转向www二级域名。

注意:URL标准化的301重定向(以上代码)需要写在其他URL-rewrite代码之前。

其它情况的方案

如果不能修改.htaccess文件,或者使用IIS系统,请同学们去搜索其它解决方案。

可参考:http://www.chinaz.com/web/2011/0125/156563.shtml

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值