Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Switch From Nested URLs to Flat URLs


Go to End


7 Posts   4014 Views

Avatar
davede

Community Member, 24 Posts

28 December 2011 at 8:44pm

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.

Avatar
BP

Community Member, 25 Posts

2 January 2012 at 11:25pm

Have you found solution for this ?

Avatar
davede

Community Member, 24 Posts

3 January 2012 at 9:24pm

No I haven't unfortunately.

Any help would be much appreciated.

Avatar
ajshort

Community Member, 244 Posts

3 January 2012 at 10:48pm

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.

Avatar
davede

Community Member, 24 Posts

4 January 2012 at 12:07am

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

Thanks again.

Avatar
ajshort

Community Member, 244 Posts

4 January 2012 at 12:39am

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.

Avatar
davede

Community Member, 24 Posts

4 January 2012 at 11:49pm

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.