簡體   English   中英

在IIS7中重定向到www-經典管道模式

[英]Redirect to www in IIS7 - classic pipeline mode

我想在IIS7 Web服務器上實現重定向。 基本上,如果URL中未包含子域,我將重定向到www子域。

http://mysite.com/file.aspx重定向到http://www.mysite.com/file.aspx

http://mysite.com/image.jpg重定向到http://www.mysite.com/image.jpg

http://mysite.com/text.html重定向到http://www.mysite.com/text.html

這個怎么做?

我不想編寫任何HTTP模塊-必須僅通過IIS配置來完成。

另外,我必須使用經典管道模式,並且無法安裝任何ISAPI插件。

可能嗎?

您可以將其放入web.config文件中:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^http://mysite.com$" />
          </conditions>
          <action type="Redirect" url="http://www.mysite.com/{R:0}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

在IIS7中,可以通過url重寫部分來完成。

此解決方案為我工作:

1)安裝URL重寫組件:

http://www.iis.net/download/urlrewrite

2)添加到web.config:

<system.webServer>
 <rewrite>
  <rules>
   <rule name="CanonicalHostNameRule1" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
     <add input="{HTTP_HOST}" pattern="^mysite\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.mysite.com/{R:1}" />
   </rule>
  </rules>
 </rewrite>
</system.webServer>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM