I have Sitecore website with URL
http://www.abc.com/our-resorts/resort1/career.aspx
But I want to shorten the URL like
http://www.abc.com/resort1/career.aspx . Any idea how to remove our-resorts
from the URL.
Please any one from Sitecore community help me ....
thanks
The first answer that comes to my mind is to use custom LinkProvider
(to generate the urls on the site) and custom ItemResolver
(to resolve items when shortened url comes).
MyLinkProvider
inheriting from Sitecore.Links.LinkProvider
and override GetItemUrl
method. If the url contains /our-resorts/
, remove our-resorts
. Of course this assumes that you don't have out items with the name our-resorts
which should not be omitted in link generation. Replace in Sitecore.config standard LinkProvider
with the new one.MyItemResolver
class inheriting from HttpRequestProcessor
and add it to the <httpRequestBegin>
pipeline directly after ItemResolver
. Code for the new item resolver:public class ItemResolver : HttpRequestProcessor
{
public override void Process(HttpRequestArgs args)
{
if (Context.Item != null || Context.Database == null || args.Url.ItemPath.Length == 0)
return;
string path = "/our-resorts" + MainUtil.DecodeName(args.Url.ItemPath);
Context.Item = args.GetItem(path);
}
}
I haven't compiled or tested the code so you need to test it on your own. If you have any more questions, post them below.
If it's not too many pages, you can just use URL Aliases in Sitecore.
They have to be setup manually for each item.
That way you can tell Sitecore that, for example, /our-resorts/resort1/career
is accessible through the URL /resort1/career
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With