IIS7 Url重写 - 从{any} .aspx重定向到{any}

时间:2010-01-19 00:43:36

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

我正在将我的网站从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做任何事情并将元重定向放入。

1 个答案:

答案 0 :(得分:2)

在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>
相关问题