admin管理员组文章数量:1291062
I have a link like this:
/?title=digital-marketing-intelligence-expert
When I surf to the page I'm redirected 404 page because the page doesn't exisit. The page doesn't exist but I would like to redirect to instead.
I also have another page like this:
/?title=sem-manager
And this is an actual page and can be found.
So I would need a check where I redirect from the 404 page to /jobs page WHEN the link start with / and can't be found. How could I do this?
I have a link like this:
https://www.example/bh-job/38/?title=digital-marketing-intelligence-expert
When I surf to the page I'm redirected 404 page because the page doesn't exisit. The page doesn't exist but I would like to redirect to https://www.example/jobs instead.
I also have another page like this:
https://www.example/bh-job/121/?title=sem-manager
And this is an actual page and can be found.
So I would need a check where I redirect from the 404 page to /jobs page WHEN the link start with https://www.example/bh-job/ and can't be found. How could I do this?
Share Improve this question asked Aug 27, 2015 at 8:23 nielsvnielsv 1731 gold badge5 silver badges17 bronze badges1 Answer
Reset to default 1I would use the wp
hook, which fires right after the request has been parsed and queried:
function wpse_199869_wp( $wp ) {
if ( ! is_admin() && is_404() && preg_match( '/^bh-job/', $wp->request ) ) {
wp_redirect( home_url( user_trailingslashit( 'jobs' ) ) );
exit;
}
}
add_action( 'wp', 'wpse_199869_wp' );
We make sure it's a 404, and check if the request (URI path) begins with bh-job
- if so, redirect to /jobs
(the user_trailingslashit
function will append or remove a trailing slash to match your permalink structure).
本文标签: url rewriting404 redirect based on url
版权声明:本文标题:url rewriting - 404 redirect based on url 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741512639a2382696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论