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

Hooking into the routing process - compute non exsting urlsegments


Go to End


2 Posts   1198 Views

Avatar
Andre

Community Member, 146 Posts

16 July 2015 at 9:45pm

Hi there, I need some good advice on how to solve the following problem.

I build a Website with lotts of pages inside a hirachical tree.

Without myself being a SEO, I did like someone suggested to me and disabled the nested urls. So every page inside the tree is accessed directly by its urlsegment, without being a followup behind its parents urlsegments and shlashes inside the url.

I also used the googlesitemaps module and google allready indexed my ~80k pages.

Now an expert suggested to me, that nested urls are far better for google to index, because it can follow a hirarchie.

My Idea now is to simply switch on nested URLs, but in the same time redirect all incoming requests for the pages original urlsegement to the new nested urlsegment.

Therefor a hook, to check if an unresolved route matches the URLSegment of a Page within the SiteTree would be ideal.
If a matching Page Object can be found, redirect to this page objects new nested url, otherwise respond with a 404 should do the trick.

But my question now is, how can I inject this logic into the router right after a matching route can not be found but before the 404 is send?

kind regards

andre

Avatar
Andre

Community Member, 146 Posts

17 July 2015 at 8:43am

Sorry for having asked that question before checking out for this functionality.

This is already implemented.

You can create your SiteTree by not using nested urls and after changing your config to use nested urls, your unested url will be automatically redirected to the nested url.

kind regards

andre