Copied to clipboard

Flag this post as spam?

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


  • Mohan 5 posts 137 karma points
    May 09, 2016 @ 07:24
    Mohan
    0

    url rewriting/customization for Umbraco 7 website

    Hi,

    How to customize the default URL pattern to user friendly url in Umbraco 7. As the url is dependent on content item name, if I change the content name of the item and publish it the url is changing. I want to come up with a solution where I can set my own url pattern as Its available in ASP.NET MVC.

    eg: DEFAULT Urls:

    • www.websitename.com/category-name/category-item-name1
    • www.websitename.com/category-name/category-item-name2

    REQUIRED Urls:

    • www.websitename.com/category-name/1
    • www.websitename.com/category-name/2
  • Stefan Kip 1591 posts 4078 karma points c-trib
    May 09, 2016 @ 07:42
  • Mohan 5 posts 137 karma points
    May 09, 2016 @ 10:42
    Mohan
    100

    Thanks Kipusoep

    I tried it and its working fine :)

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 06:54
    Tajamal
    0

    Hi Kipusoep

    what if i have a url : www.mysite.com/news/2016/some-news

    and rewrite that to: www.mysite.com/news/some-news

    How would i achieve that, i tried to do the above but doesn't solve my problem i am going through, any tips would be appreciated ?

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Jun 23, 2016 @ 07:21
    Michaël Vanbrabandt
    0

    Hi Tajamal,

    the property umbracoUrlName only changes the url for the node. With this you can't remove parent elements from the url.

    For this you can use the url rewrite config file in umbraco. There you can write a new rule to remove the year from the news url.

    Documentation about the url rewriting in .net can be found here

    /Michaël

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 08:18
    Tajamal
    0

    Hi Michael

    I tried the following rule from the example, but that doesn't seem to have any effects. Do you have any idea what I should try?

    <add  name="redirect_news"
                  virtualUrl="^~news/2016/(.*)"
                    rewriteUrlParameter="ExcludeFromClientQueryString"
                    destinationUrl="~/news/$1"
                    ignoreCase="true" />
    

    Many thanks for a quick reply much appreciated.

    /Tajamal

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Jun 23, 2016 @ 08:39
    Michaël Vanbrabandt
    0

    Tajamal,

    can you try the following rule:

    <add name="NewsRule"
        virtualUrl="^~/news/(.*)"
        destinationUrl="~/news/2016/$1"
        rewriteUrlParameter="ExcludeFromClientQueryString"
        ignoreCase="true" />
    

    You have switched both urls. The virtual url is the one you will use and is not known in the umbraco system. The destinationurl will be the url that replaces the virtual url.

    /Michaël

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 09:11
    Tajamal
    0

    I am getting following error when i try that.

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'TestProject.Models.ErrorPageView'.

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Jun 23, 2016 @ 09:24
    Michaël Vanbrabandt
    0

    Can you show me the code of the view?

    /Michaël

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 09:21
    Tajamal
    0

    I tried that again and got following Url: /news/2016/2016

    so yes, it is working in some way. but not what i want.

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Jun 23, 2016 @ 09:26
    Michaël Vanbrabandt
    0

    What url are you using that gives this result?

    If you go to http://www.mysite.com/news/some-news then you should see the page of http://www.mysite.com/news/2016/some-news

    /Michaël

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 09:27
    Tajamal
    0

    Shouldn't i get redirected to " /news/" when i visit this page "/news/2016" ?

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Jun 23, 2016 @ 09:34
    Michaël Vanbrabandt
    0

    No because of the rule you created you will be redirected to ~/news/2016/2016/.

    That is the problem when you want to create custom routes. You could create a new rule for this but then you have to do it for all the years that have to come; eg 2017 / 2018 / 2019, ...

    /Michaël

  • Tajamal 69 posts 157 karma points
    Jun 23, 2016 @ 10:38
    Tajamal
    0

    I wanted to rewrite to hide the year from path by paths "/news/2016" and "/news/2016/some-news".

    so basically I am stuck? I don't mind writing the rules for years, I can live with that for now.

  • Tajamal 69 posts 157 karma points
    Jun 24, 2016 @ 04:59
    Tajamal
    0

    I ended up moving all child node to "News" node by manually updating umbracoNode table.

    It just doesn't look nice with all the news articles and neither I'm sure of how it will perform loading all the news over time in a single node.

  • Sotiris Filippidis 262 posts 1340 karma points
    Jun 25, 2016 @ 09:58
    Sotiris Filippidis
    1

    Maybe this one could come in handy if you need to just hide some url part? I created it some time ago to avoid having to specify weird rewritings and have some flexibility. https://our.umbraco.org/projects/website-utilities/virtualnodes/

  • Tajamal 69 posts 157 karma points
    Dec 01, 2016 @ 11:57
    Tajamal
    0

    I finally got to implement your solution and its working good. :)

    Now, here is my question, do you have a nuget package for this solution?

  • Sotiris Filippidis 262 posts 1340 karma points
    Dec 01, 2016 @ 12:02
    Sotiris Filippidis
    0

    Not yet - but I'm going to make one soon, since other people have requested it too.

  • Tajamal 69 posts 157 karma points
    Dec 01, 2016 @ 12:04
    Tajamal
    0

    great - it's a problem when you have to deploy the solution to different environments.

  • Tajamal 69 posts 157 karma points
    Jun 27, 2016 @ 10:58
    Tajamal
    0

    It looks very handy, it gives better structure in umbraco and have simplified url up front.

    Thanks a lot :)

Please Sign in or register to post replies

Write your reply to:

Draft