Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roland Egedi 5 posts 85 karma points
    1 week ago
    Roland Egedi
    0

    Best way to have custom Url

    I'm using Umbraco 8.3 and I am (very) new to Umbraco CMS.

    So I would like some help/advice on the following topic, it would be greatly appreciated!

    Is it possible to somehow remove a segment of the Url for a page that it gets because it is a child?

    Or to somehow set the Url of a page to only the Url alias of the page (umbracoUrlAlias)?

    Let me explain what I mean below. If I have a structure like this:

    + Home
    ++ Blog
    +++ Blog post 1
    +++ Blog post 2
    ++ About
    

    For the blog posts it would give me the Url:

    • mysite.com/blog/blog-post-1
    • mysite.com/blog/blog-post-2

    But I want it to have (with no "blog"-segment):

    • mysite.com/blog-post-1
    • mysite.com/blog-post-2

    If I use "umbracoUrlAlias" it still keeps the mysite.com/blog/blog-post-1 Url. I don't want this Url to work, or at-least not to be the default Url (item.Url).

    "umbracoUrlName" only seems to replace the last segment, the "page name”, but can’t change the path?

    Perhaps I could use IIS Rewrite Module or maybe Custom MVC Route. But that seems like overkill, but maybe it is the only way?

    What would be the best / a good / solution for this problem?

    Also, a second question! How do I get all the alias Url’s set for a page? I can get the Url by eg “item.Url” but I can't find eg a “item.UmbracoUrlAlias”?

    Thanks!

    /R

  • Marc Goodson 1024 posts 6755 karma points MVP 4x c-trib
    1 week ago
    Marc Goodson
    100

    Hi Roland

    The best way would be to write a custom UrlProvider and a custom IContentFinder to work in tandem to customise what item.Url produces and to map that Url to the particular Content item.

    Umbraco ships with a DefaultUrlProvider which provides the current logic for generating Urls, you could create a new c# class that inherits from this, but which only applies to a certain Document Type, to control completely what the Url will be for an item.

    There is an example in the docs for adding the word 'fish' to all Urls that you may be able to work from:

    https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/outbound-pipeline#example-1

    Now how does the incoming request map to your content if it doesn't follow Umbraco's default convention?

    There is a series of IContentFinders who try one after another to map incoming Urls to Umbraco content following different mapping rules - you can create your own implementation, with your own custom logic, and add this to the queue of Finders.

    There is an example of an IContentFinder here:

    https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder

    So your UrlProvider would remove 'Blog' from the Url, and your IContentFinder would find a blog post in the 'Blog' section of the site based on it's UrlName.

    With regard to your second question, umbracoUrlAlias will create 2 Urls for your content item, the original Url and the umbracoUrlAlias defined Url - generally the workaround to avoid SEO penalties is to add a meta CanonicalUrl for one of the Urls, so search engines know to treat the two Urls as one.

    and in order to get the umbracoUrlAlias value...

    var urlAlias = item.Value<string>("umbracoUrlAlias");
    

    should be what you need.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft