IIS Host Headers and non WWW to WWW

和自甴很熟 提交于 2019-12-02 11:42:48

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

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!