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:
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.
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.
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 :P
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'?
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.