2014-03-04 80 views
1

輸入:domainname.com/name如何在web.config文件(iis 7.5)中重寫url?

輸出:domainname.com/page.aspx?n=name

我曾嘗試下面的代碼。

<rewrite> 
    <rules> 
     <rule name="RedirectToWWW" stopProcessing="true"> 
      <match url=".*" ignoreCase="true" /> 
      <conditions> 
       <add input="{HTTP_HOST}" pattern="^domain.com$" /> 
      </conditions> 
      <action type="Redirect" url="page.aspx?n={R:0}" redirectType="Permanent" /> 
     </rule> 
    </rules> 
</rewrite> 

它很酷。但是,如果我只輸入域名,那也可以重寫以避免這個問題?

+1

你忘記添加你的代碼了嗎? – shenku

回答

0
Oh my god ! finally got the solution. 
<rewrite> 
    <rules> 
     <rule name="RedirectToWWW" stopProcessing="true"> 
      <match url="^(.+)$" /> 
     <conditions logicalGrouping="MatchAll"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
      </conditions> 
      <action type="Redirect" url="page.aspx?n={R:0}"/> 
     </rule> 
    </rules> 
</rewrite>