不带www域名重定向到带www域名
我们知道,网站域名通常包括不带的域名和到带的域名,很多时候,为了SEO优化的需要,我们要将不带域名重定向到带域名,下面就介绍一下具体的实现方法。
Apache
编辑网站根目录下的。htaess 文件,在文件里增加如下内容
RewriteEnge on
rewriteCond %{http_host} ^williamlong.fo [NC]
rewriteRule ^(.)$ http://.williamlong.fo/$1 [L,R=301]
IIS
在IIS 7.0以上的版本,有一个跟.htaess非常类似的文件web.config,功能也非常强大,编辑根目录下的web.config文件,在文件里增加如下内容
<?xml version="1.0" encodg="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" sProcessg="true">
<match url="." />
<conditions>
<add put="{HTTP_HOST}" pattern="^williamlong.fo$" />
</conditions>
<action type="Redirect" url="http://.williamlong.fo/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
如果用户网站支持https的话,可以将重定向地址也修改为https,至于http如何重定向到https,请参考此文IIS和APACHE实现HTTP重定向到HTTPS。
推火专家月光博客