I have an issue with IIS7 url rewrite module, when I add following rule I get an 404 error on all pages.
<rule name="Remove .aspx" stopProcessing="true">
<match url="(.+)\.aspx" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
All I want to do to remove all files extensions.
I get lost with this, maybe someone knows the solution?
Thanks in advance.
Regards,
eimeim
Best Answer
Removing .aspx from the URL by redirecting the user to the URL without .aspx is only one part of the solutions.
If you do that redirect, how will the server ever know what script (with .aspx extension) to execute if the URL doesn't contain the correct name (without .asp extension)? So you have to add a rule to fix that. The way to do that is to make a rule that matches any URL, but doesn't match any existing file or directory. If we encounter that, we can assume that it might be a rewritten link to an ASPX page so we rewrite the URL to add .aspx. If it isn't an ASPX page it will result in a 404 anyway.
To make it all work with your existing code you have to outbound rewrite the response of your pages to remove all existing references to .aspx pages to not include the extension. Otherwise you will get a lot of unnecessary redirects and form posts to aspx pages will not work anymore.
Last but not least you have to disable compression as the outbound rewriting does not work with compression turned on.
This all results in the following rewrite rules for you web.config: