locked
Simple Rewrite - Hide all ".ASPX" file extensions RRS feed

  • Question

  • User-1005863443 posted

    Hi there,

    I'd basically like to have user friendly URLs on my new web project. All pages are going to have the file extension of ".aspx" so instead of "http://www.mywebsite.com/projects/edit-project.aspx?id=123" I think it would be better for it to read "http://www.mywebsite.com/projects/edit-project/?id=123" or just "http://www.mywebsite.com/projects/edit-project?id=123" (no trailing forward slash)

    I can get my head around doing individual URL rewrites using the IIS Rewrite module but I can't figure out how to apply the rule to every page?

    Hopefully someone can help :)

    Wednesday, March 23, 2011 12:43 PM

Answers

  • User-327639713 posted

     Hi,

    You can use the following rules to achieve your requirement:

    <rewrite>
       <rules>
                    <rule name="RemoveASPX" enabled="true" stopProcessing="true">
                        <match url="(.*)\.aspx" />
                        <action type="Redirect" url="{R:1}" />
                    </rule>
                    <rule name="AddASPX" enabled="true">
                        <match url=".*" negate="false" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="{R:0}.aspx" />
                    </rule>
      </rules>
    </rewrite>

    Thanks

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Friday, March 25, 2011 1:54 AM

All replies

  • User-327639713 posted

     Hi,

    You can use the following rules to achieve your requirement:

    <rewrite>
       <rules>
                    <rule name="RemoveASPX" enabled="true" stopProcessing="true">
                        <match url="(.*)\.aspx" />
                        <action type="Redirect" url="{R:1}" />
                    </rule>
                    <rule name="AddASPX" enabled="true">
                        <match url=".*" negate="false" />
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                            <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
                        </conditions>
                        <action type="Rewrite" url="{R:0}.aspx" />
                    </rule>
      </rules>
    </rewrite>

    Thanks

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Friday, March 25, 2011 1:54 AM
  • User-1005863443 posted

    Thanks very much,

     Sorry for the (very) late reply but finally got round to using this and it works great!

    Friday, April 22, 2011 5:56 AM
  • User1003697099 posted
    I am new to using the rewriting tool.  If I take the rules above and put them in my web config I get all sorts of errors (unrecognized).  Is there a way to import a file with that text to the rules in iis?
    Friday, April 22, 2011 4:32 PM
  • User2074017181 posted

    worked. Thank you!

    Monday, January 28, 2013 11:30 AM