2011-04-04 98 views
1

我爲Windows服務器上承載的項目使用標準web.config文件。它需要處理2個任務。web.config索引重定向

  1. 它將網站的非www版本重定向到www版本。
  2. 它將索引文件重定向到根。

見下文:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
     <rewrite> 
      <rules> 
       <rule name="CanonicalHostNameRule1" stopProcessing="true"> 
        <match url="index\.asp(?:l)?" /> 
         <conditions> 
          <add input="{HTTP_HOST}" pattern="example\.com$" /> 
         </conditions> 
         <action type="Redirect" url="http://www.example.com/" /> 
       </rule> 
       <rule name="CanonicalHostNameRule2" stopProcessing="true"> 
        <match url="(.*)" /> 
        <conditions> 
         <add input="{HTTP_HOST}" pattern="^example\.com$" /> 
        </conditions> 
        <action type="Redirect" url="http://www.example.com/{R:1}" /> 
       </rule> 
      </rules> 
     </rewrite> 
    </system.webServer> 
</configuration> 

這個偉大的工程,除1個問題。索引重定向將所有子目錄重定向到主索引。

例如:

http://www.example.com/index.asp像它應該被重定向到http://www.example.com

但是,http://www.example.com/about/index.asp也重定向到http://www.example.com。我想它重定向到http://www.example.com/about/

任何幫助將不勝感激。

回答

4

那麼,在沒有得到迴應後,我發佈了各種.Net論壇,最後得到了答案。這條規則將解決它:

<rule name="redirect index.asp" stopProcessing="true"> 
    <match url="^(\w*/)?index\.asp" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="domain\.com$" /> 
     </conditions> 
    <action type="Redirect" url="http://www.domain.com/{R:1}" /> 
</rule> 
+0

不錯的工作和感謝張貼! – worked 2012-08-25 23:50:27