How to create multiple URLs for the same content based on a custom property?
In Umbraco 11 I'm trying to solve this problem.
I have a Product page (based on a Product document type). This document type has a PartNumbers property consisting of a string containing a whole series of codes separated by a # character.
My goal is to be able to reach to Product page with each of the part numbers (so for example /product, /part-number-1, /part-number-2 ecc...).
I could use hostnames, but for a single product I can have hundreds of part numbers. So this can't work. I was thinking to combine the IUrlSegmentProvider with the IContentFinder, but with this approach I'm not able to create multiple urls, but only a single one.
By checking whether (the path of) the url matches/contains one of the codes in the PartNumbers property of the Product page. If there is a match, redirect the page to the Product page.
Could be something like this (quickly written from the top of my head, so it's not directly usable, but to show you the idea):
var requestUrl = HttpContext.Request.Url;
var partNumberFromUrl = //filter the part number from the requestUrl
var partNumbers = productPage.PartNumbers.Split('#');
if (partNumbers.Contains(partNumberFromUrl))
{
HttpContext.Response.Redirect(productPage.Url);
}
These will then appear in the backoffice as options for editors.
The 'order' of your UrlProviders define what Url is written out when you write
@Model.Url in a template
and similarly the order of the IContentFinders define what will be matched, only the first content match wins....
... so in extreme circumstances you could have it finding the wrong content if the PartNumber was the same as a Node Name... but not if you make sure your ContentFinder that looks for the PartNumber is before the default ContentFinder that Umbraco ships with in the queue of ContentFinders!
How to create multiple URLs for the same content based on a custom property?
In Umbraco 11 I'm trying to solve this problem.
I have a Product page (based on a Product document type). This document type has a PartNumbers property consisting of a string containing a whole series of codes separated by a # character.
My goal is to be able to reach to Product page with each of the part numbers (so for example /product, /part-number-1, /part-number-2 ecc...).
I could use hostnames, but for a single product I can have hundreds of part numbers. So this can't work. I was thinking to combine the IUrlSegmentProvider with the IContentFinder, but with this approach I'm not able to create multiple urls, but only a single one.
Hi,
Maybe redirects can solve your problem.
By checking whether (the path of) the url matches/contains one of the codes in the PartNumbers property of the Product page. If there is a match, redirect the page to the Product page.
Could be something like this (quickly written from the top of my head, so it's not directly usable, but to show you the idea):
I would not like to use redirects, since for SEO reasons we need to have a different page for each part number.
The top solution would be to have different "urls" for the same product page, one for each part number.
In this way our product page would be always the same, but for search engines, we would have a different page for each part number.
Hi ema-bianchetti
You can have multiple IContentFinders or a single IContentFinder that can look for content based on multiple criteria...
and similarly with an IUrlProvider you can define 'Other' URLs by implementing GetOtherUrls
https://github.com/umbraco/Umbraco-CMS/blob/33adbf41fa1f5c5d0759c70a7116114107addf56/src/Umbraco.Core/Routing/IUrlProvider.cs#L40
These will then appear in the backoffice as options for editors.
The 'order' of your UrlProviders define what Url is written out when you write
@Model.Url in a template
and similarly the order of the IContentFinders define what will be matched, only the first content match wins....
... so in extreme circumstances you could have it finding the wrong content if the PartNumber was the same as a Node Name... but not if you make sure your ContentFinder that looks for the PartNumber is before the default ContentFinder that Umbraco ships with in the queue of ContentFinders!
regards
Marc
is working on a reply...