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
- Allow requests to resources outside the wordpress folder
- htaccess – Redirect to subfolder without changing browser URL
- Generic htaccess redirect www to non-www
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- Masking wp-content/themes/name/images to just images directory using htaccess
- Passing parameters to a custom page template using clean urls
- How to add custom rewrite rule to .htaccess?
- Use subdomain for certain urls
- add_rewrite_rule: $matches var not replaced by captured value
- Custom permalinks with NextGEN Gallery
- Clash of the rewrites
- How to change default page slug?
- How to remove “admin.php?page=” from wp-admin using .htaccess?
- SEO Friendly URLs for my plugin categories
- Will references to ugly links automatically redirect to their pretty url permalink?
- How do I add a add_rewrite_rule without it redirecting?
- How do I remove a word from a url in WordPress using .htaccess?
- Hijacking the URL for filtering
- Rewrite rules in .htaccess get overwritten?
- Custom rewrite rules are sending everything to index.php
- WP Login forms action URLs displayed as pretty URLs in browser (ex with Restore Password)
- Sub domain redirection to taxonomy
- custom htaccess rewrite rule for page
- How do I skip wordpress’s 404 handling?
- WordPress keeps writing rewrite rules to .htaccess
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- WordPress Rewrite
- Dynamic URL, not a physical page within the database
- unexpected problem in url rewrite
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Prevent WordPress from automatically correcting URLs
- Why is there /index.php/ in all my links? How do I remove it?
- Two “.htaccess” Files Located in Different Directories?
- WordPress redirection to get url friendly
- Using a custom field value to redirect away from a 404 page
- WordPress removes spaces in URL on pagination
- Using WP rather than .htaccess to redirect pages/posts
- htaccess: Remove trailing slash from URL ending with .xml/ only
- External/non-WP rewrite rule without QSA
- Issue with using .htaccess to redirect feedburner feed
- Remove all categories from URL
- Home page with Polylang redirects to other page [closed]
- Remove special characters in a URL
- 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
- Map alt domain to specific section of website w/o MU
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- Is there a ‘rake routes’ for wordpress?
- Remove Query String from URL on Redirect – Redirection Plugin
- Deny access to a path (give 403 or 404 response)
- Rewrite rule to load images from production does nothing
- Cleanup URL for a custom page in wordpress
- How to disable the default WordPress redirect to non-www URLs?
- WordPress rewrite rules don’t need ^?
- WordPress SSL (https) is not working with custom permalink
- Changing RSS feed URL structure
- How to redirect http://mydomain/blog/blahblah/ to http://mydomain/blahblah/ in wordpress htaccess?
- Adding rewrite rules directly to .htaccess file
- Access files at new location using old file paths
- Issue with htaccess redirection in WP Multisite
- NextGEN Gallery Lightbox – Social Share URL Redirect
- How do I redirect all 404 error url to Subcategory url
- Url Rewriting a dynamic wordpress page
- WordPress .htaccess blocks mine?
- Preserve Domain Alias
- WordPress redirects non-existing url to existing ones – how to disable
- My WP_options db rewrite_rules Does Not Work
- Disable Pagination on Pages
- Custom Permalink
- How to disable URL rewriting for specific URLs?
- WordPress Redirecting Non Category Pages /page/nnn to their Canonical URLs
- subdirectory install breaking existing links
- a one-off rewrite rule