Reputation: 343
I want to do URL Redirect and Rewrite using the Rules written in config file, I am using the Umbraco (CMS of .Net) and here is the 2 config file which are RewriteRules.config and UrlRewriting.config.
What I need actually
I have an URL like : http://localhost:50777/node1/node2/node3/node4/node5/
Should be: http://localhost:50777/node5/
OR
http://localhost:50777/node1/node2/node3/node4/
Should be: http://localhost:50777/node4/
I want to remove the parent node from URL and show only the last node URL which shows the correct page content but in my case its giving me 404 Error that page not found.
So I have to write some Rules in config file which rewrite the truncated URL path to exact path.
Please give me any solution for this, Thanks.
Upvotes: 0
Views: 481
Reputation: 500
These two may do what you need by adding in UrlRewriting.config:
<add name="FiveNodeRewriteRewrite"
virtualUrl="^~/node1/node2/node3/node4/(.*)"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1"
ignoreCase="true" />
<add name="FourNodeRewriteRewrite"
virtualUrl="^~/node1/node2/node3/(.*)"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1"
ignoreCase="true" />
These are assuming your nodes are static named in your example. If you need something more dynamic, perhaps this example:
<add name="FiveDynamicNodeRewriteRewrite"
virtualUrl="^~/(.*)/(.*)/(.*)/(.*)/(.*)"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$5"
ignoreCase="true" />
<add name="FourDynamicNodeRewriteRewrite"
virtualUrl="^~/(.*)/(.*)/(.*)/(.*)"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$4"
ignoreCase="true" />
Upvotes: 0