2010-01-19 42 views
4

我将我的网站从Asp.Net Webforms转换为Asp.Net MVC。我想重定向所有旧的.aspx文件以删除.aspx。我运行安装了Url Rewrite模块的IIS7。IIS7 Url Rewrite - 从{any} .aspx重定向到{any}

例子:

/about.aspx - > /约

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

如何使用Url重写来做到这一点?我不想要做的每一个的.aspx并放入元重定向

+0

你想用户输入site.com/about.aspx的网址重定向到about controller或用户输入site.com/about重定向到aspx页面? – Odd 2010-01-19 01:39:32

回答

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>