I have been struggling with the following for quite some time now:
Default url:
examplesite.com/folder/about.cshtml
Desired url:
examplesite.com/about
Basically I want to accomplish two things:
- 1 Remove the file extension with realtively compact code.
- 2 Remove the folder that houses the about page.
I have found some uncommon rules to achieve all the above, but they mostly contain a lot of redundant code that crashes my site when I test it with IIS 8.0.
So I was hoping someone could share a rule that is compact and fits my needs. Or seperate rules with the same outcome.
Every contribution is much appreciated :)
I'm not certain I entirely understand your needs, but here's something that's at least close. It strips out the first folder and file extension (so
examplesite.com/folder/about.cshtml
becomesexamplesite.com/about
andexamplesite.com/folder/help/about.cshtml
becomesexamplesite.com/help/about
). If you wanted to strip all folders then just remove the?
.Update:
Ok, I think what you want is a combination of two rules then:
The first rule makes sure that all requests are to friendly URLs. The second takes the friendly URL and rewrites it to your physical path, where the physical path is
folder/[FRIENDLY_PATH].cshtml
.