Do I need IVirtualPageController?

There is a “Shop” page at the route, so the URL is “/shop” which is good.

Under “Shop” there is a “products” container page, with “Product” pages underneath it. Each Product page has a “Category” picker so that we can assign products to one or more categories … or none is also OK.

There is also a “categories” container page, with “Category” pages underneath it.

So, the Umbraco structure is:

> Site
    Categories
        Category A
        Category B
    Products
        Product 1
        Product 2

The requirement is to have URLS like (1):

/shop/category-a
/shop/category-a/product-1

Also, links direct to products would work (2):
/shop/products/product-1

So, (2) is standard Umbraco which is fine, but what is the best way to achieve (1)? Remove the “categories” part of the URL and the link to the products in each category to maintain the “/shop/category-a/” part and not revert to “/shop/products/”

Is this what IVirtualPageController is for?

Yes, achieving the desired URL structure in Umbraco requires customizing the routing. IVirtualPageController is one approach, but a more straightforward way to handle this is by using Content Finders and custom URL routing.

Would you be able to expand on your answer, maybe with some code samples or a link to an example? Other than the standard Umbraco documentation which I was not able to get anything useful from.

Umbraco by default tries to get a node based on the supplied URL. If it fails, you can have multiple (I)ContentFinders that implement custom logic to find a node. It will go through all available content finders until one finds a node (or more specifically, sets the context item). And there is a LastChanceContentFinder you could use to return a 404 node or something (it will always have a 404 status code).

Read more about it here: IContentFinder | Umbraco CMS.

So in short: links that already work because of the default Umbraco routing. Links that don’t work and don’t resolve to a node can handled by ContentFinders to ‘find’ the content for Umbraco based on custom logic. I don’t think it rewrites the URL in the browser.

@LuukPeters thanks for the pointer / info. I have now got the IContentFinder working.

My next problem is “faking” the breadcrumb.

The route to the page is “/shop/category/product” but “product” is actually in “/shop/products”.

So I get a breadcrumb of “/shop/products” instead of “/shop/category” which is where you access the product page from :thinking:

Any ideas on how to solve that?

Actually, I used the Request.Path data to figure out the parts

A third option… urlRewrites either in IIS rewrite rules… or in the UseRewriter Middleware.
app.UseRewriter(new RewriteOptions().AddRewrite(@"^shop/category/(product)", "shop/products/$1", skipRemainingRules: true))

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.