Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am using UmbracoUrlAlias for having custom urls and I want the page to be redirected to custom url if UmbracoUrlAlias is set whenever user clicks on any node/link available in web page. User should not see the original url on browser when the umbracoUrlAlias is set in CMS.
There are a number of ways of handling this scenario...
The simplest, way is probably to only write out links to content using what you have set for the umbracoUrlAlias
so if you are building a navigation menu and using @navItem.Url to write out the link, instead have a custom method that checks umbracoUrlAlias of the navItem first, and if it's populated use that instead of the .Url property.
On the page itself add a Canonical Meta tag with the value of the UmbracoUrlAlias... this means if anyone visits the page on the original default Url, they will still see the page, but there won't be any penalisation in SEO search indexing, as all requests to the Url will be counted underneath the single Canonical Url, eg no need for redirects!
One consideration you'll have is that umbracoUrlAlias takes a comma delimited list of multiple Urls... so you probably want to split on a , and have the convention that the first UrlAlias in the list is the canonical one!
If you are determined to have a redirect, the next simplest way is to handle the PublishedRequest Prepared event:
PublishedRequest.Prepared += PublishedRequest_Prepared;
This is fired just before your page is rendered, so you 'could' check the incoming request, and check the content it's matched, and see if it has a populated umbracoUrlAlias page, and instead of allow the page to be rendered, redirect to the umbracoUrlAlias value to start the processing of the request again.
Thirdly when a request comes into Umbraco, a series of 'IContentFinders' try one after another in a queue to match the Url of the incoming request to a content item in Umbraco.
If the ContentFinder makes a match, then the rest of the ContentFinders don't get a chance to find a match, and the content item is rendered.
There IS a ContentFinder called ContentFinderByUrlAlias
and this executes 'before' ContentFinderByUrl, which matches the original 'default' url for the content item.
So another option would be to create a custom ContentFinder RedirectOriginalUrlToUrlAliasContentFinder() and copy the ContentFinderByUrl implementation
but instead of returning the content, you would check for the umbracoUrlAlias value, and put the redirect in there.
You'd then register your Custom ContentFinder 'before' the ContentFinderByUrl finder in the queue...
lots of options!, but I usually do the first one!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted