Currently I have a rewrite rule in my web.config that removes the ".aspx" page extension.
I want to rewrite my URL to remove the whole page name "page1.aspx" so my URL will show as "www.mysite.com/folder/" and not "www.mysite.com/folder/page1"
My rewrite code in the web.config I currently use is the following :
<rewrite>
<rules>
<clear />
<rule name="Redirect to clean URL" enabled="true" stopProcessing="true">
<match url="^([._0-9a-z-/]+).aspx$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="RewriteASPX" enabled="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
</rewrite>
What do I need to add or edit to my current rules to get the results I need?
Thanks!
Quickly testing it on regex101.com, does this work?
<match url="^([._0-9a-z-/]+)/(.+).aspx$" ignoreCase="true" />
and
<action type="Redirect" url="{R:0}/" />
Adding the "/(.+)" makes sure the last word before aspx gets removed from the first match (R:0). R:1 will contain that word: "page1" while R:0 will contain:"www.mysite.com/folder".
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.