asp.net重定向非www链接到www

时间:2012-01-18 20:21:25

标签: asp.net redirect url-rewriting

我有一个在IIS 7.5上运行的经典asp.net站点。我在网页配置文件中添加了以下重写信息,用于将非www链接重定向到www

 <?xml version="1.0"?>
    <configuration>
        <system.web>
          <customErrors mode="RemoteOnly" defaultRedirect="/404.html">
            <error statusCode="404" redirect="/404.html" />
          </customErrors>
        </system.web>
        <system.webServer>
          <httpErrors>
            <clear />
            <error statusCode="404" subStatusCode="-1" path="/404.html" responseMode="ExecuteURL" />
          </httpErrors>

<!-- code added -->
          <rewrite>
            <rules>
              <rule name="Redirect" patternSyntax="ECMAScript" stopProcessing="true">
               <match url=".*" />
               <conditions>
                <add input="{HTTP_HOST}" pattern="^domain.com$" />
               </conditions>
               <action type="Redirect" url="http://www.domain.com/{R:0}" />
             </rule>
           </rules>
         </rewrite>
<!-- code added -->
       </system.webServer>
    </configuration>

是的,重写模式未启用,现在可以正常工作。

0 个答案:

没有答案