Copied to clipboard

Flag this post as spam?

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


  • Bobi 352 posts 956 karma points
    Mar 06, 2017 @ 05:04
    Bobi
    0

    Url issue - remove folders from url

    I cannot seem to figure out how to remove a folder from the url. For example, if a site's root is at / and you have a structure like so:

    Home - Folder - SubContent1 -SubContent2

    The url to subcontent1 is: /folder/subcontent1.

    Is there any way to remove the "folder" portion from /folder/subcontent1, so it is /subcontent1?

    umbracoHideTopLevelNodeFromPath is set to true in web.config, and I have tried all of the below, but they do not achieve the abovementioned goal of removing "folder" from the url.

    1. umbracoRedirect (content picker)
    2. umbracoInternalRedirectId (content picker)
    3. umbracoUrlName (textstring)
    4. umbracoUrlAlias (textstring)

    Thanks.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 06, 2017 @ 12:34
    Dan Diplo
    1

    I believe this package might be what you are looking for:

    https://our.umbraco.org/projects/backoffice-extensions/omit-segments-url-provider/

  • Bobi 352 posts 956 karma points
    Mar 06, 2017 @ 19:25
    Bobi
    0

    This is great, thanks, I'll check it out. Is there a way to do this natively?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 06, 2017 @ 19:37
    Dan Diplo
    0

    Only by writing your own URL provider, which I imagine is quite tricky:

    https://our.umbraco.org/documentation/reference/routing/request-pipeline/outbound-pipeline

  • Micha Somers 134 posts 597 karma points
    Mar 06, 2017 @ 21:02
    Micha Somers
    0

    If you want to implement it yourselves, there are mutliple ways to get there...

    You can use

    • IIS url rewrite rules (if rewriting can be done by convention) or
    • UrlProviders and ContentFinders (if application logic is needed to return correct content, or for the parts that are harder to write with url rewrites)

    Maybe you can use an example of an UrlProvider for stripping out a part of the url (in this example /companies/companyABC => /companyABC)

    class CompanyUrlProvider : IUrlProvider
    {
        public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
        {
            return Enumerable.Empty<string>();
        }
    
    public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
        {
            var content = umbracoContext.ContentCache.GetById(id);
            //  Company url that starts from root
            if (content != null && content.DocumentTypeAlias == "umbCompany")
            {
                //The company node will have /<company> instead of /companies/<company>.
                return String.Format("/{0}/", content.UrlName);
            }
            return null;
        }
    }
    
  • Bobi 352 posts 956 karma points
    Mar 06, 2017 @ 21:19
    Bobi
    0

    Thanks Micha. How would you go about to do the IIS url rewrite?

  • Micha Somers 134 posts 597 karma points
    Mar 06, 2017 @ 21:25
    Micha Somers
    0

    In a somewhat similar discussion some examples of IIS url rewrites are shown: https://our.umbraco.org/forum/using-umbraco-and-getting-started/80821-umbraco-content-structure-advice#comment-258459

Please Sign in or register to post replies

Write your reply to:

Draft