0

I got the requirement from our client that he wants to render the Page instead of page item name with the specific field text.

Ex: I have a page item name as "findyourmarket". So this page will browse by https://domainname/findyourmarket. Now this page has a field "SEO URL" and value is "Find-your-market". Now this page will be rendered as https://domainname/Find-your-market.

We have suggested the "display name" property and Aliases concept but he is not agreed with those.

If any inputs are really helpful for us. Thanks in advance.

  • Try with custom Item resolver. Patch it after Item resolver. Logic: you need to check the whole Site tree to resolve this item. There may be a performance impact. – Siva Kumar Apr 23 '19 at 6:37
  • 5
    I might add; you should be reluctant to allow requirements such as these split your solution apart and take you away from established Sitecore Best Practices. Display Name is the official Sitecore way of achieving this - anything else is sending you off on a wrong path. – Mark Cassidy Apr 23 '19 at 7:05
  • You might consider copying the seo url field into the display name? Although I would follow Mark on this.. why would a customer not want to use the display name? And why do you have a seo-url field? – Gatogordo Apr 23 '19 at 8:48
  • Just a side note given the name of the url field... if you are worried about SEO then having multiple URLs that resolve to the same content is not good. Make sure to use canonical tags to help identify the SEO url as the 'real' url. – Jason St-Cyr Apr 23 '19 at 12:25
5

To create custom URL's based on a custom field, you will have to write your own linkprovider and plug it in. https://doc.sitecore.com/developers/sxa/17/sitecore-experience-accelerator/en/add-and-select-a-custom-link-provider.html

With the link provider you can generate different URL's.

Next, you need to add a custom itemresolver in the httprequestbegin pipeline to translate the url back into the item. In this class you will need to read the url, and find the item using your custom "SEO url". You will need to set the sitecore context item.

public class CustomItemResolver : HttpRequestProcessor
{
    public override void Process(HttpRequestArgs args)
    {
        var path = args.Url.ItemPath;
        var item = FindItem(path);

        if (item != null)
        {
            Context.Item = item;
        }
    }
}
| improve this answer | |
  • Thanks @Bart. This code snippet really help us. – kalikrishna Apr 23 '19 at 15:24
-1

If it is about getting SEO friendly names then you can use <encodeNameReplacements> configuration from Sitecore.config. Create a patch file for this and add configuration to replace spaces(" ") and other symbols with SEO friendly names. This would not effect item names and happens at runtime. Sitecore will handle it out of the box. The example patch can look like this:

<configuration>
    <sitecore>
        <encodeNameReplacements>
            <replace mode="on" find=" " replaceWith="-" />
        </encodeNameReplacements>
    </sitecore>
</configuration>

Otherwise, If this is not the case then I would support the solution given by Bart.

I hope this helps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.