Jump to:

22997 Posts in 11844 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Switch From Nested URLs to Flat URLs

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 994 Views
  • davede
    Avatar
    Community Member
    24 Posts

    Switch From Nested URLs to Flat URLs Link to this post

    Hi Guys,

    We would like to switch from using nested URLs to flat URLs to enable greater flexibility in moving pages around the site tree without destroying their URL.

    I can see that it is easy to disable nested URLs by removing:

    SiteTree::enable_nested_urls();

    from the config.php file.

    However unlike when switching TO nested URLs the redirects do not appear to be handled automatically. Is there a way that we can configure SS to redirect the old nested URLs to the flat ones? or do we have to use the .htaccess file? If so any code hints would be much appreciated.

  • Zyzzza
    Avatar
    Community Member
    25 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    Have you found solution for this ?

  • davede
    Avatar
    Community Member
    24 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    No I haven't unfortunately.

    Any help would be much appreciated.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    There's no inbuilt support for this, but it should be relatively easy to implement. Just create a custom front controller which pops the last part off the request URL, checks for a SiteTree record with a matching URLSegment, and then redirects to there.

  • davede
    Avatar
    Community Member
    24 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    Hi Aj,

    Thanks so much for replying here. From what I understand you wrote the code to handle hierarchical URLs in the first place! Fantastic stuff.

    I'm not too familiar with the inner workings of SS

    Would you be able to provide any hints with the coding as you are most likely more familiar than most when it comes to this area? Or could you point me in the right direction for creating 'custom front controllers'?

    Thanks again.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    Maybe take a look at https://github.com/ajshort/silverstripe-linkmapping/blob/master/code/controllers/LinkMappingFrontController.php and the related code in _config.php. The code is a bit hacky, but works. Instead of the LinkMapping::get_by_link() call in the main function, you would want to perform your lookup for a SiteTree object which has a URLSegment matching the last part of the requested URL.

  • davede
    Avatar
    Community Member
    24 Posts

    Re: Switch From Nested URLs to Flat URLs Link to this post

    Hi Aj,

    Thanks for getting back to me. Your help on the matter is very much appreciated. I have spoken with our developer and he should be able to figure it out based on the info you've provided.

    I'll let you know how it works out and the solution we reach in order to help any others trying to achieve the same thing.

    994 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.