Jump to content

Moved page with url segments not found with page path history


NikNak
 Share

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...