【问题标题】:ASP.NET 4.0 Rewrite Rules in Global.aspx File Issues with rewriteGlobal.aspx 文件中的 ASP.NET 4.0 重写规则 重写问题
【发布时间】:2013-01-25 12:45:08
【问题描述】:

我在 IIS7 上的 ASP.NET 4.0 中使用了一个重写规则:

<system.webServer>
<rewrite>
  <rules>
    <rule name="Rewrite default to aspx" stopProcessing="true">
      <match url="^$" ignoreCase="false" />
      <action type="Rewrite" url="home.aspx" />
    </rule>
  </rules>
</rewrite>
<defaultDocument>
  <files>
    <add value="home.aspx" />
  </files>
</defaultDocument>
</system.webServer>

此规则采用:(http:/example.com/aboutus.aspx) 并从 URL 的末尾删除 .aspx。我在子域 (http:/www.example.com/blog) 上安装 wordpress 时遇到问题,由于我的重写规则,我收到以下错误:

描述:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保其拼写正确。

请求的 URL:/blog/.aspx

有谁知道我可以如何修复 URL 重写规则,使其安全地到达 (http://www.example.com/blog/) 并且不在末尾添加 .aspx?

是否有某种语法可以搜索博客子目录以忽略目录'/blog/'?

非常感谢!谢谢! :)

【问题讨论】:

    标签: url-rewriting


    【解决方案1】:

    如果您希望您的规则适用于除/blog/* 之外的每个网址,那么您可以使用否定选项:

    <rule name="Rewrite default to aspx" stopProcessing="true">
      <match url="^blog/" ignoreCase="false" negate="true" />
      <action type="Rewrite" url="home.aspx" />
    </rule>
    

    http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_pattern_properties

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2014-07-17
      • 2011-02-23
      • 2014-01-23
      • 2014-09-26
      • 2012-12-06
      相关资源
      最近更新 更多