As far I understand, .htaccess rewrite rules are executed before the request is proccesed by WordPress, or even by PHP engine, so you can not know if a URL will trigger a 404 error in .htaccess, you can not check if a given path will trigger a 404 at that level. You need to do it in WordPress itself:
// See https://developer.wordpress.org/reference/hooks/template_redirect/
add_action( 'template_redirect', 'cyb_redirect_not_found_paths' );
function cyb_redirect_not_found_paths() {
// See https://developer.wordpress.org/reference/functions/is_404/
if( is_404() ) {
if( $_SERVER['REQUEST_URI'] == '/your_path' ) {
$url_to = 'redirecton_rul';
// See https://developer.wordpress.org/reference/functions/wp_redirect/
wp_redirect( $url_to );
exit;
}
}
}
Related Posts:
- Site loads very slowly (4-5 minute load time)
- 301-redirect directives for blogger to wordpress migration
- Redirect – remove custom query string
- How do I do a redirect to WordPress permalink with post id via htaccess?
- Can I redirect the http request towards an old folder to the homepage using .htaccess file? [closed]
- htaccess – Redirect to subfolder without changing browser URL
- Redirect old php link to wordpress link in .htaccess
- Cant login to wp-admin (redirecting to homepage), But CAN login to wp-login.php
- Cant login to wp-admin (redirecting to homepage), But CAN login to wp-login.php
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- WordPress redirecting connections on port 8080 to 80
- Redirect entire website to a single page
- Redirecting WordPress /.htaccess / HSTS / SSL
- Site redirects to wrong url when saving settings
- Htaccess redirect from ‘/%postname%.html’ to ‘/%postname%’
- WordPress site redirects to different wordpress domain on the same server after reuploading db backup
- Index in root, wordpress in subdirectory
- Redirect www to non-www htaccess
- Specific URL has 403 Forbidden status code
- Redirect to https not working with .htaccess [closed]
- htaccess redirect – directory and subpages to a single page
- htaccess redirect dynamic posts
- RedirectMatch and Redirect interfering with each other
- Menu links only using http after enabling https, unable to redirect http links
- Why specific file directory fails to redirect but its parent folder succeeds?
- WordPress site in subdirectory load site in main directory
- https multiple redirects
- Why does multisite bypass WordPress for wp-content, wp-admin, wp-includes and .php files?
- some url does not redirect from http to https
- Why can’t I access files / directories outside of wordpress
- Redirect blogpage /blog/abcd/ to /blog/
- How to redirect from various ?page_id= to home page?
- WordPress redirecting to 127.0.0.1 when accessing the site from a remote device
- Redirect all pages except one to homepage via .htaccess
- Redirect 301 www.my-site.com/page/n to www.my-site.com/ [closed]
- Headless WordPress redirect front-page to login page [closed]
- htaccess redirects and WordPress
- 301 Redirect To Post ID
- htaccess rules not applied?
- Use virtual pages point to one specific page
- htaccess redirect – replace special character
- How to add new redirection on wordpress site
- Load time cost of using a redirect plugin v direct .htaccess entry
- htaccess redirect invoice.php to /client/invoice.php
- How to set 301 redirection after moving WordPress blog?
- Redirecting amp url to non amp url
- Redirect homepage with htaccess, except if I enter the link adding “/home”
- Redirect all requested url to new url
- 301 redirection editing .htaccess doesn’t work
- Redirect custom post type from one domain to another domain
- Redirections and rewrites to subdomain
- How To Fix 404 errors caused by Google Indexing WordPress In Subdirectory
- Can’t control WordPress Addresses from admin panel
- Unable to access folders in same level as wordpress installation
- Redirect htaccess does not work correctly with my new wordpress site
- reducing number of URL Redirects and increasing speed
- 301 Redirect all page and post urls from .html to /
- How to use https on one page only?
- .htaccess 301 redirect conflict with plugin “WordPress Https”
- How do I put up a splash page and have all WordPress links redirect to this page?
- Redirect specific URL before other redirects take place in .htaccess?
- Prevent wordpress autoredirect
- Stop forcing certain paths to end with a forward slash
- How to redirect the frontend of a WordPress site (only)?
- Permalinks do not include www subdomain
- I want to resolve Redirect Chain [closed]
- How to fix URL with pageid example /?p= too many redirection error
- 301 redirect any RSS feed on level up url
- How to redirect an old page url to the homepage
- redirecting an entire WP site from one top level domain to another
- Redirection with a wildcard
- Date based redirects of posts that no longer exist
- WordPress redirect to new domain name
- 301 all old pages to new location
- Open wordpress page in directory the way index.html would open
- Use a 301 to Redirect any 404 from at the blog post level to the blog archive
- Understanding Redirects
- Error in /blog redirection – ubuntu default WP installation
- 301 Redirect Loop www to non-www – Nginx + Apache2
- how to redirect 404 to attachment.php?
- 302 redirect *.at/site redirecting to .comsite
- Using cache brokes redirecting
- 301 Redirect in WordPress not working in htaccess
- Loading /wp-content/uploads/site as /site/
- Redirect after login when WordPress in subdirectory
- Redirect after Permalink change – What regex do I use?
- Allow GET request on certain page
- .htaccess redirect for old subfolder installation to new subfolder installation and https
- How to 301 redirect to subdirectory but keep access to wp-admin of main domain
- Pagination redirect set in .htaccess file is not working
- Redirecting a POST to a php script
- htaccess and redirect to new url using regex
- How to redirect correctly a root domain to a subdomain in a subfolder?
- How to permanent redirect old domain to new one. in case amazon store
- Need rewrite for URL with specific string
- How to redirect all pages of a blog to a new blog
- WordPress subfolders htaccess bypassing the root htaccess RewriteRule
- How does the flow of htaccess files in sub-directories work
- How to Redirect Url to homepage?
- Redirect old homepage to the new one within the same site