I 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).
Related Posts:
- Redirecting all old links from previous EE site to new WP site in one go?
- Server (WordPress) redirects files that are not supposed to (using htaccess)
- Rewrite WordPress Custom URL
- Custom rewrite rule
- Alias ‘wp-content’ directory to something shorter (framework?)
- add_rewrite_rule fro html to another url not working
- Double domain name in category URL-s
- Rewrite Preview URL to include index.php
- How to remove wordpress directory slash
- Wildcard forward all posts and pages with few exceptions
- Redirecting /px/?q=x to /px/x/
- URL redirect on updating the post date
- Rewrite vs Redirect from ?p={ID}
- Is WordPress API visible from PHP file called in htaccess
- Redirect htaccess [closed]
- 301 Rewriting htaccess
- Redirect empty search to another page
- Fresh install redirects to www, breaking page loads
- Error 404 wordpress redirecting URL
- Redirect A URL Pattern In WordPress Using .htaccess
- Migration from old CMS to WordPress 301 redirection rules?
- Stop wordpress to redirecting home page if no page found
- Changes done to .htaccess are not getting reverted back
- Post pages are redirecting to the 404 page in wordpress
- htaccess – Redirect to subfolder without changing browser URL
- Masking wp-content/themes/name/images to just images directory using htaccess
- How to add custom rewrite rule to .htaccess?
- Use subdomain for certain urls
- Clash of the rewrites
- How to change default page slug?
- Hijacking the URL for filtering
- Custom rewrite rules are sending everything to index.php
- Sub domain redirection to taxonomy
- custom htaccess rewrite rule for page
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- unexpected problem in url rewrite
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Two “.htaccess” Files Located in Different Directories?
- Using a custom field value to redirect away from a 404 page
- WordPress removes spaces in URL on pagination
- Home page with Polylang redirects to other page [closed]
- Add query string to url and display it as normal url part /folder/
- Why specific file directory fails to redirect but its parent folder succeeds?
- expecting 404 but redirecting to post with url subdirectory in post title
- WordPress .htaccess – route other URLs to another app
- hard flush_rewrite_rules() not regenerating .htaccess
- Remove Query String from URL on Redirect – Redirection Plugin
- Deny access to a path (give 403 or 404 response)
- Cleanup URL for a custom page in wordpress
- WordPress rewrite rules don’t need ^?
- Changing RSS feed URL structure
- Adding rewrite rules directly to .htaccess file
- Issue with htaccess redirection in WP Multisite
- Preserve Domain Alias
- WordPress redirects non-existing url to existing ones – how to disable
- Can I change default registration link (without htaccess)?
- Cannot access wp-admin without trailing slash – .htaccess configuration for WordPress behind a nginx proxy
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- Replace specific middle part of url
- Rewriting a subdomain page on one WordPress installation to a parent domain on another
- How to redirect large amount of URLs?
- How to create a front end user profile with a friendly permalink and a 404 trigger
- Attachment page gives 404 if user not logged
- Customise particular RSS permalink
- RSS feed rewrite matching wrong rule
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- How to redirect Webp files?
- How can I redirect users on the new 404 page without plugin?
- Thousands of 404 errors on old posts due to embedded links
- How do I make WordPress revise an .htaccess file a certain way?
- How are rewrite rules applied in WordPress?
- Adding Theme File for Non-WordPress Content
- Show index.php template instead of 404 page template
- Redirect to new domain that serves new and different content
- Redirect users with “.” (dot) in their username and replace with “-” (dash) to correct profile
- Rewrite htacess rule doesn’t work
- multisite 404 subfolder same name slug as site
- Translatepress taxonomy and custom post type root FIX
- WordPress URL redirect and replace ? question mark
- Custom taxonomy named ‘tag’ return 404 page
- Multiple permalink with and without category for same post
- Custom Params in URL
- Param causing 404
- Broken page redirect
- WordPress Category url redirects to subdomain
- Add ReWrite from Old Pages to WordPress (remove .php)
- Remove trailing slash
- Changing post per page causing 404 for pagination. Need a redirect htaccess rule
- Fully mask *all* traces of WordPress installation subdirectory?
- .htaccess RewriteRule to include post type and taxonomy
- How to create short urls for sharing and downloadable content?
- Subpages return 404 server error
- Rewrite Question
- Additional .htaccess rules based on wp page
- How to change search url produced by ‘s GET method?
- how to rewrite folder name in url to another name
- Add rewrite endpoint and .htaccess
- Using .htaccess to redirect /da/ to / in URL
- WP-Include rewrite directory
- How to disable WordPress canonical redirect to nearest matching URL and force 404 Page?