I have a custom post type containing job listings, that is highly volatile. Jobs are frequently added and removed. Our analytics show that a lot of crawling errors are for detail pages of jobs that have been unlisted.
The solution I came up with is to redirect all visits for non-existant URLs within the CPT’s slug to the job listing overview, and I would like to automate this.
How would I go about this? I’m looking for a solution that does this very early and skips as much unnecessary calls as possible. (i.e. something earlier than doing this in header.php, ideally as an action)
Example:
mydomain.com/jobs/existingjob/
delivers the detail page for the jobmydomain.com/jobs/nojobhere/
does not exist and would throw a 404 but instead gets redirected to
mydomain.com/jobs/