Copied to clipboard

Flag this post as spam?

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


  • Derrik 29 posts 98 karma points
    Oct 25, 2013 @ 16:05
    Derrik
    0

    Removing a directory from URL

    I am building a website with a large product catalog on v6.1.6 and would like to organize the products by alphabetical folders in the CMS. However, I do not want the alpha folders to be displayed in the URL.

    Here is the node structure:

    • Products
      • A
        • Product
        • Product
      • B
        • Product
        • Product
      • C
        • Product
        • Product

    The goal is for the URL to look like this:
    /products/calibrachoa-superbells-yellow/

    Instead of this:
    /products/c/calibrachoa-superbells-yellow/

    I thought there might be a way to do this with URL rewriting, but I haven't been able to figure it out. Any help would be appreciated. Thanks.

     

  • Yuri Derevianko 7 posts 27 karma points
    Oct 26, 2013 @ 18:37
    Yuri Derevianko
    0

    Hi Derrik,

    URL rewriting is intended to convert input "virtual" url from browser into site's legal url. So for this to work somehow it is needed to produce urls which already "virtualized".

    I've been solving the same problem recently. After digging docs an so on I've come to next solution:

    1. Established razor function CoolUrl (because used razor) which gets doc id, calls umbraco.NiceUrl on it and then via string.Replace("smth", "") removes certain part from url. Everywhere in the project (breadcrumbs, menus etc) to produce url I call my CoolUrl instead umbraco's NiceUrl. As result all the urls on page are produced without annoying portion.

    2. To react correctly on clicking those urls I used url rewrite engine (/config/UrlRewriting.config). The only important thing I have no clue for is how to take the first letter from product's name in url and put it as /a/, /b/, /c/ so on. Probably regex used in UrlRewriting allows do that. Because my site is not that big, I used several rewriting rules in .config file based on unique portion of url which allow to rewrite url unambiguously.

    Hope this helps somehow. 

Please Sign in or register to post replies

Write your reply to:

Draft