Copied to clipboard

Flag this post as spam?

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


  • Andreas Älveborn 31 posts 52 karma points
    May 07, 2012 @ 14:20
    Andreas Älveborn
    0

    UrlRewriting to unknown folder

    Hello

    I have a structure like this:

    Information
    - Subfolder1
    - - Page1
    - - Page2
    - Subfolder2
    - - Page3
    etc.

    I want the viewer only to see the url /information/page but is it possible to redirect to the correct page while excluding the subfolder in the url?
    Like this:
    /information/Page3 redirects to /information/subfolder2/page3
    and
    /information/Page2 redirects to /information/subfolder1/page2

    I guess I could hard code the redirects but is there a way to do this dynamic?

  • Mike Chambers 636 posts 1253 karma points c-trib
    May 08, 2012 @ 10:33
    Mike Chambers
    0

    If Page1, Page2, Page3 are intended to be unique... then you could write something based on the 404 redirect wiki... [http://our.umbraco.org/wiki/how-tos/how-to-implement-your-own-404-handler] (changing the status code/header so it's not a 404 but the mechanism you require.)

    You'd then have to take the URL and grab the page name eg Page1, then implement an xpath lookup on the full umbraco nodeFactory to find the instance where the unique page name matches... You can change the Xpath to be as specific or global as you want depending on your strucutre.

     

    XPathNavigator xpn = umbraco.content.Instance.XmlContent.CreateNavigator();
    XPathNavigator node = xpn.SelectSingleNode("//DocumentType [@nodeName = "+YOUR PAGE NAME+"]");

    Once you have your node it's a simple thing to redirect or rewrite the incoming page to the actual umbraco path using NiceUrl.

     

Please Sign in or register to post replies

Write your reply to:

Draft