url在iis7中重写

时间:2011-04-05 15:10:11

标签: asp.net iis-7 url-rewriting

我正在运行IIS7.5和URL Rewrite模块。

我按照这些分步说明启用了用户友好的网址:

  

Rule Templates for the URL Rewrite Module - User Friendly URL - rule template

如果我输入网址http://domain.com/default/而非http://domain.com/default.aspx网站会引发404: file not found error

以下是我的重写规则:

<rewrite>
  <rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
      <match url="^demourl\.dev\.asenetechdev1\.com/default\.aspx$" />
      <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
      </conditions>
      <action type="Redirect" url="demourl.dev.asenetechdev1.com/default" 
              appendQueryString="false" />
    </rule>
    <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
      <match url="^demourl\.dev\.asenetechdev1\.com/default$" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="false" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
      </conditions>
      <action type="Rewrite" url="demourl.dev.asenetechdev1.com/default.aspx" />
    </rule>
  </rules>
  <outboundRules>
    <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
      <match filterByTags="A, Form, Img"
             pattern="^(.*)demourl\.dev\.asenetechdev1\.com/default\.aspx$" />
      <action type="Rewrite" value="{R:1}/ demourl.dev.asenetechdev1.com/default" />
    </rule>
    <preConditions>
      <preCondition name="ResponseIsHtml1">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

我也尝试过使用Intelligencia.UrlRewriter。但是我能够在本地和服务器上生成友好的URL,但是我想要无扩展的URL,它在我的本地服务器上工作正常,但不在实时服务器上。

1 个答案:

答案 0 :(得分:1)

您的模式目前不匹配/默认/。它只是匹配/默认

更改

<match url="^demourl\.dev\.asenetechdev1\.com/default$" />

<match url="^demourl\.dev\.asenetechdev1\.com/default/{0,1}$" />

应该这样做。