【问题标题】:url rewriting in iis7iis7中的url重写
【发布时间】:2011-07-30 01:48:32
【问题描述】:

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

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

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

如果我输入 URL 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,它在我的本地服务器上可以正常工作,但在实时服务器上不行。

【问题讨论】:

  • 您忘记包含您的web.config 设置...

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


【解决方案1】:

您的模式当前与 /default/ 不匹配。它只匹配 /default

变化

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

到

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

应该这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 2013-04-09
    • 2023-03-17
    • 2012-01-01
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多