输入:domainname.com/name
输出 : 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>
它工作很酷。但是如果我只输入域名,那也会重写。如何避免这个问题?
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>