2010-01-19 51 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>