Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rewrite or shorten the Sitecore URL

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.

enter image description here

Please any one from Sitecore community help me ....

thanks

like image 852
Sam Avatar asked Dec 04 '22 08:12

Sam


2 Answers

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).

  1. Create your own class 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.
  2. Create 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.

like image 94
Marek Musielak Avatar answered Feb 20 '23 17:02

Marek Musielak


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

enter image description here

like image 45
Ruud van Falier Avatar answered Feb 20 '23 17:02

Ruud van Falier