IIS主机标头和非WWW到WWW [英] IIS Host Headers and non WWW to WWW

查看:186
本文介绍了IIS主机标头和非WWW到WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于如何将非www重定向到您的www网站的示例,但我没有使用任何重写utils / ISAPI。

I know there's a bunch of examples on how to redirect your non www to your www site, but I'm not using any rewrite utils/ISAPI.

On我的Windows 2008R2框,我在IIS中设置了几个站点。我为www和非www版本设置了主机头。前几个网站工作正常。如果您尝试访问非www网站,则会自动重定向到www版本。

On my Windows 2008R2 box, I have several sites setup in IIS. I setup host headers for both www and non www versions. The first couple of sites work fine. If you try to go to the non www site, you are automatically redirected to the www version.

据我所知,我没有做任何特别的事情。除了添加适当的主机头之外 - 不要乱用重写/ ISAPI。

As far as I recall, I didn't have to do anything special other than add the appropriate host headers - no messing around with rewrites/ISAPI.

为了让这个工作起作用,我在服务器管理器方面缺少什么?

What am I missing on the server manager side of things in order to get this working?

推荐答案

我想有两种方法。一种是通过IIS管理器创建重写规则。

I guess there are two ways. One is to create a rewrite rule through the IIS manager.

另一种是设置web.config的system.webserver部分,如下所示:

The other is to setup the system.webserver section of the web.config as follows:

  <system.webServer>

    <rewrite>
      <rules>
        <clear/>
        <rule name="Redirect Non WWW to WWW" enabled="true" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>

        <!--<rule name="Default Document" stopProcessing="false">
          <match url="(.*)default.aspx"/>
          <action type="Redirect" url="{R:1}" redirectType="Permanent"/>
        </rule>-->

      </rules>
    </rewrite>

    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>

    <httpErrors errorMode="Custom"/>

  </system.webServer>

这篇关于IIS主机标头和非WWW到WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆