开发者

IIS7 Url Rewrite - Redirect from {any}.aspx to {any}

开发者 https://www.devze.com 2022-12-16 16:11 出处:网络
I am converting my website from Asp.Net Webforms to Asp.Net MVC.I want to redirect all my old .aspx files to drop the .aspx.I run IIS7 with the Url Rewri开发者_运维百科te module installed.

I am converting my website from Asp.Net Webforms to Asp.Net MVC. I want to redirect all my old .aspx files to drop the .aspx. I run IIS7 with the Url Rewri开发者_运维百科te module installed.

Example:

/about.aspx -> /about

The user will go to http://www.site.com/about.aspx and I want them redirected to http://www.site.com/about.

How do I do this using Url Rewrite? I don't want to have to do to each .aspx and put a meta-redirect in.


In your web.config file in system.webServer configuration section add:

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消