2014-03-04 50 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>