happyxp 发表于 2019-5-16 15:44:15

IIS环境下web.config伪静态实现301跳转(www与不带www

IIS下面做域名301的跳转实际上是比较简单的,两种方法:
第一种:直接在IIS里面新建一个网站绑定不带www的域名然后设置301跳转到www域名即可。

第二种:需要开启伪静态,所以相对来说麻烦点,如果你已经开启rewrite伪静态了,那就简单多了。
IIS开启rewrite伪静态传送门(建设中。。。)

1.windows2003+iis6.0系统通过httpd.conf实现:
用记事本打开编辑修改网站根目录的httpd.conf,在下面添加对应代码
#此规则表示站点上所有域名都301跳转到www.xp6.org
RewriteCond %{HTTP_HOST} !^www.xp6.org$
RewriteRule ^(.*)$ http://www.xp6.org/$1
#此规则表示如果访问是xp6.org就跳转到www.xp6.org,有多个就复制多组规则2.windows2008+iis7(windows2012+iis8)系统通过web.config实现301
将以下规则复制到记事本内,保存为web.config(注意xp6.org、abc.com替换为自己的域名)上传到网站根目录。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
      <rewrite>
            <rules>
                <rule name="301Redirect" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}" pattern="^xp6.org$" />
                        <add input="{HTTP_HOST}" pattern="^abc.com$" />
                  </conditions>
                  <action type="Redirect" url="http://www.xp6.org/{R:0}" redirectType="Permanent" />
                </rule>
            </rules>
      </rewrite>
    </system.webServer>
</configuration>


页: [1]
查看完整版本: IIS环境下web.config伪静态实现301跳转(www与不带www