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”?
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:
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.
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");
Hi Marc.
I am currently trying to implement a custom Urlprovider following the example from step 3. create url's https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/outbound-pipeline.
i have now copied the code that should add 'fish' to all Urls and registered it on a composer. have implemented it, to only apply to a documenttype with alias 'area'.
and the composer works, but i get an error when checking page url on the area documenttype. there is no url just the error: This document is published but its url cannot be routed
i am developing on a local iis with a new umbraco 8 install and i have not changed any config settings so far, i have just added the composer and the custom urlProvider. do you know what the problem could be ?
Yes, in the backoffice, Umbraco is checking that any Urls generated by the UrlProviders for a particular content item 'can be routed'. To find this out, it runs the Url through the queue of ContentFinders... to see if the Url can be mapped to content...
... if it can't map the Url back to a content node, you get the message saying it can't be routed...
So if you now create an IContentFinder, (https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder) that looks for /fish on the end of the incoming url, but then 'finds' the content 'without' the fish part or returns a specific fishy node for all requests ending in /fish... then the message should go away...
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:
For the blog posts it would give me the Url:
But I want it to have (with no "blog"-segment):
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
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...
should be what you need.
regards
Marc
Hi Marc. I am currently trying to implement a custom Urlprovider following the example from step 3. create url's https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/outbound-pipeline. i have now copied the code that should add 'fish' to all Urls and registered it on a composer. have implemented it, to only apply to a documenttype with alias 'area'. and the composer works, but i get an error when checking page url on the area documenttype. there is no url just the error: This document is published but its url cannot be routed i am developing on a local iis with a new umbraco 8 install and i have not changed any config settings so far, i have just added the composer and the custom urlProvider. do you know what the problem could be ?
Hi Roland
Yes, in the backoffice, Umbraco is checking that any Urls generated by the UrlProviders for a particular content item 'can be routed'. To find this out, it runs the Url through the queue of ContentFinders... to see if the Url can be mapped to content...
... if it can't map the Url back to a content node, you get the message saying it can't be routed...
So if you now create an IContentFinder, (https://our.umbraco.com/Documentation/Reference/Routing/Request-Pipeline/IContentFinder) that looks for /fish on the end of the incoming url, but then 'finds' the content 'without' the fish part or returns a specific fishy node for all requests ending in /fish... then the message should go away...
regards
Marc
is working on a reply...