简体   繁体   中英

Premanently redirect .php or .aspx to an extensionless asp.net MVC page

thought the following was working but it turns out not to. I want to redirect the following pages for example. The original site was php then moved to aspx and now mvc.

http://www.example.com/page/one.aspx

http://www.example.com/page/one.php

to

http://www.example.com/page

The IIS Rewrite rile that I created is below but it needs tweaking.

<rule name="PHPToASPNET" stopProcessing="false">
<match url="(.*)\.php$" />
<conditions logicalGrouping="MatchAll">
  <add input="{URL}" negate="true" pattern="\.axd$" />
  <add input="{URL}" negate="true" pattern="\.xml$" />
  <add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>  
<action type="Redirect" url="http://www.example.com/{ToLower:{R:1}}" redirectType="Permanent" /

Try this

<rule name="PHPToASPNET" stopProcessing="true">
<match url="^(.*)/(.*)\.(php|aspx)$" />
<conditions logicalGrouping="MatchAll">
    <add input="{URL}" negate="true" pattern="\.axd$" />
    <add input="{URL}" negate="true" pattern="\.xml$" />
    <add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{ToLower:{R:1}}" redirectType="Permanent" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM