Copied to clipboard

Flag this post as spam?

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


  • Alice 4 posts 24 karma points
    May 30, 2014 @ 17:41
    Alice
    0

    How to insert UmbracoUrlAlias using backend editor?

    We are using UmbracoUrlAlias instead of standard Umbraco Urls.  

    While editing docs using TinyMCE when you are trying to insert internal link to another page with UmbracoUrlAlias TinyMCE inserts umbraco Url like {localLink:1069}. As a result we have standatd Umbraco Url at the link. But we need to insert UmbracoUrlAlias, because we do not use standard Urls at all. Is there any easy way to solve that?

    Thanks!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 30, 2014 @ 21:37
    Jan Skovgaard
    0

    Hi Alice and welcome to our :)

    There is no way that you can pick the url alias using when choosing internal url's - if you need to hit a certain alias then you can add the link as an external url instead.

    However I think it sounds as a bit odd way of dealing with linking if all your pages have an url alias?

    /Jan

  • Alice 4 posts 24 karma points
    May 30, 2014 @ 22:52
    Alice
    0

    Hi Jan!

    Many thanks for quick reply!

    It's not good if we cannot use internal urls because that option is available at the link editor and I don't know how to disable it. A lot of managers are working with content in our company and they will try to use it:(.

    Anyway I'll explain why we are using alias for all links. Our website page urls do not correspond with website structure at all. For example, internal product page path is "products > business > ocr > finereader >corporate", but the url of that page should be "/finereader_corporate/". Because of SEO and so on. Do you have any idea how it could be solved without using aliases for all pages?

    Thank you in advance:).

    Alice 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 31, 2014 @ 09:55
    Jan Skovgaard
    0

    Hi Alice

    You can use internal url's indeed - BUT if you have added one or more aliases to a specific page, which means the page can be hit on the default url defined by the page name and one or more url aliases the url picked in the editor will be the default url rather than the url alias, which you will have to enter like an external url.

    Instead of using aliases it seems to be more appropriate to be using url rewrites instead - Have a look in the /config/UrlRewriting.config file - I believe this is the approach you need to take instead - But it's not an area that I'm an expert in how to setup the url rewriting though. But probably others in here can help or it should be possible to figure out how to write the rules by googling and following the link in the comments for the file I mentioned.

    Hope this helps.

    /Jan

  • Alice 4 posts 24 karma points
    Jun 02, 2014 @ 13:40
    Alice
    0

    Hi Jan!

    Thank you for your response.

    I know how to create url rewrite rules, but I don't think it is what we need. Because our content editors (they are not web masters) need to create and change custom urls via backend. So the requirement is to have custom url field at administrative interface anyway. Maybe we need to redirect "true" urls to aliases, but we cannot do that via UrlRewriting.config.

    Do you know the reason why Umbraco does not support it? I think it's common for corporate websites to have (for example) contacts under Company section, but page url should be www.company.com/contacts, not www.company.com/company/contacts.

    Alice

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 03, 2014 @ 21:30
    Jan Skovgaard
    0

    Hi Alice

    Well if you need to make a redirect then you should use the umbracoRedirect property instead, which you can read more about here http://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracoredirect - That will do what you want - However please be aware that the built in redirect is doing a 302 - In the bottom of the article there is a link to a package that uses a 301 redirect - However, not sure if it will work on your version of Umbraco?

    But then it should be possible to customize it yourself I suppose so the editor can choose the alias of the url instead.

    Hope this helps.

    /Jan

  • Alice 4 posts 24 karma points
    Jun 06, 2014 @ 12:12
    Alice
    0

    Hi Jan!

    Thank you. That could be a solution, but our seo specialists don't like it. Because navigation links should be direct links, not redirects.

    It seems that the only one way for us is to use aliases. Maybe we could develop our own custom button for Tiny, which inserts links to aliases instead of "true" links.

    Alice 

  • Roman (rc21) 7 posts 72 karma points
    Jul 18, 2014 @ 22:59
    Roman (rc21)
    1

    This problem can be resolved by adding you own custom Url Provider to Umbraco.

    To do this you need first of all create provider class UrlAliasProvider (for example) with such content:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Core;
    using Umbraco.Web;
    using Umbraco.Web.Routing;
    
    namespace TheOutfield.Routing
    {
        public class UrlAliasProvider : IUrlProvider
        {
            public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
            {
                var node = umbracoContext.ContentCache.GetById(id);
                return node.HasValue("umbracoUrlAlias")
                    ? "/" + node.GetPropertyValue<string>("umbracoUrlAlias") + "/"
                    : null;
            }
    
            public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
            {
                return Enumerable.Empty<string>();
            }
        }
    }

    Secondly you need 'register' you provider in umbraco by creating ApplicationEventHandler:

    using TheOutfield.Routing;
    using Umbraco.Core;
    using Umbraco.Web.Routing;
    
    namespace TheOutfield
    {
        public class Bootstrapper : IApplicationEventHandler
        {
            public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            { }
    
            public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                UrlProviderResolver.Current.InsertTypeBefore<DefaultUrlProvider, UrlAliasProvider>();
            }
    
            public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            { }
        }
    }
  • Robert Foster 459 posts 1820 karma points MVP 2x admin c-trib
    Jul 21, 2014 @ 15:27
    Robert Foster
    0

    Hi,

    Chances are you won't need the second class (Bootstrapper) - Umbraco will automatically load any class that implements IUrlProvider.  At least, 6.x and 7.x should anyway.

    - Rob.

  • Roman (rc21) 7 posts 72 karma points
    Jul 22, 2014 @ 13:44
    Roman (rc21)
    0

    Hi, Robert

    I have checked your guess, but it's not working for me: without implementating IApplicationEventHandler Umbraco (7.1.4. in my case) doesn't load IUrlProvider.

  • Robert Foster 459 posts 1820 karma points MVP 2x admin c-trib
    Jul 22, 2014 @ 13:57
    Robert Foster
    0

    Yup, looks like you're right...

Please Sign in or register to post replies

Write your reply to:

Draft