Reputation: 313
My site has multiple directories in. All the aspx pages are in directory "SitePages". Example, http://example.com/Sitepages/page1.aspx
http://example.com/Sitepages/pagexyz.aspx
i need a url-rewrite rule to strip out the directory and extension like: http://example.com/Sitepages/page1.aspx becomes http://example.com/page1
if the site is on https or has www infront of domain name, the rule shouldn't change that.
The rule should also change the absolute urls entered by user to these friendly urls.
Example, if user enters http://example.com/Sitepages/page1.aspx , then the browser should show http://example.com/page1
So i guess two rules are needed.
Also the rule should be applicable on the directory "Sitepages" only.
The rule should not be case-sensitive.
I tried a few rules but they don't work properly. I tried these:
<rule name="RewriteUserFriendlyURLS" enabled="true" stopProcessing="true">
<match url="^([a-zA-Z0-9_-]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="sitepages/{R:1}.aspx" />
</rule>
Also tried this:
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.aspx$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="sitepages/{R:0}.aspx" />
</rule>
Please help.
Upvotes: 0
Views: 1070
Reputation: 3952
To redirec users to friendly urls you need rule:
<rule name="Test" stopProcessing="true">
<match url="^.*Sitepages.*\/(.*).aspx$" />
<action type="Redirect" url="{R:1}" />
</rule>
To handle friendly urls you need rule:
<rule name="Test2">
<match url="^.*Sitepages.*$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
Upvotes: 0