NikNak Posted June 7, 2016 Share Posted June 7, 2016 Hi there I have a an events section using urls such as: /events/1234/text-generated-from-headline where 1234 is the page id of the event and 'text-generated-from-headline' is a url-segment for SEO purposes only Once an event is passed, it is automatically moved to: /events/past-events/1234/text-generated-from-headline I did this so that the event could always be found using the page id, regardless of the extra url segment text which sometimes makes for a long and ugly url, and the likelihood of the event title being updated, without the user changing the page 'name' correspondingly. The problem I've found now, is that anyone with a 'current' URL for an event that has now passed, is getting a 404 error, because page path history cannot follow the correct path, unless the url segment is removed. ie '/events/1234/' will redirect to '/events/past-events/1234/' but '/events/1234/blah' will not redirect to '/events/past-events/1234/blah' My question is whether there is a way to intercept the Page Not Found, run a routine to test if the URL looks like an event, and remove the url segments and redirect again. I've tried something akin to $wire()->addHook('ProcessPageView::pageNotFound', null, 'RedirectEvent') but its not getting me anywhere. I could always add code to the 404 page template, but this would mean two re-directs being performed, which I guess would be bad for SEO. Many thanks Nik Link to comment Share on other sites More sharing options...
adrian Posted June 7, 2016 Share Posted June 7, 2016 Take a look at: http://modules.processwire.com/modules/process-redirect-ids/ It may work as is for your needs, or you can take a look at the approach used as it also hooks into ProcessPageView::pageNotFound 1 Link to comment Share on other sites More sharing options...
NikNak Posted June 8, 2016 Author Share Posted June 8, 2016 Thanks so much for the steer Adrian. I'll check that out - fingers crossed I will be able to work up a solution with this. All the best Nik Link to comment Share on other sites More sharing options...
NikNak Posted June 8, 2016 Author Share Posted June 8, 2016 Just tested this and it solves the issue completely. I just set it to work on 'Event' templates and use /{$page->id}/ for the id format and it does the trick. Thanks so much Adrian. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now