【问题标题】:IIS7 Url Rewrite - Redirect from {any}.aspx to {any}IIS7 网址重写 - 从 {any}.aspx 重定向到 {any}
【发布时间】:2010-01-19 00:43:35
【问题描述】:

我正在将我的网站从 Asp.Net Webforms 转换为 Asp.Net MVC。我想重定向我所有的旧 .aspx 文件以删除 .aspx。我在安装了 Url Rewrite 模块的情况下运行 IIS7。

例子:

/about.aspx -> /关于

用户将转到http://www.site.com/about.aspx,我希望他们重定向到http://www.site.com/about。

如何使用 Url Rewrite 执行此操作?我不想对每个 .aspx 做任何事情并放入元重定向。

【问题讨论】:

  • 您希望用户在site.com/about.aspx的url中输入重定向到about控制器还是用户输入site.com/about重定向到about aspx页面?跨度>

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


【解决方案1】:

在 system.webServer 配置部分的 web.config 文件中添加:

<rewrite>
  <rules>
    <rule name="WebFromsToMVC" stopProcessing="true">
      <match url="^(.*?)\.aspx\?*?.*$" />
        <conditions>
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
      <action type="Rewrite" url="{R:1}" />
    </rule>
  </rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    相关资源
    最近更新 更多