First, I’ll say it’s beyond me why you’d want to do this, I really don’t think it’s a good idea, but in any case…
If you look in /wp-includes/canonical.php
, you’ll see how WP is fighting you on this. The only way I’m aware of to get around it is to go looking for the post yourself based on the post id query var (which should be set and hopefully correct) and resetting the $wp_query
global to whatever is found, then manually setting the status header so a 404 isn’t sent to the browser.
function wpse27871_404_fakeout() {
global $wp_query;
if( $wp_query->is_404 && get_query_var('p') ):
$this_query = new WP_Query( 'p='.get_query_var('p') );
if( $this_query->post_count !== 0 ):
$wp_query = $this_query;
status_header(200);
endif;
endif;
}
add_action('wp', 'wpse27871_404_fakeout');
Related Posts:
- Stop WordPress and Plugins from Overwriting .htaccess
- 301 Redirects for Changed Permalink Structure & Category Base
- How do I turn off 301 redirecting posts (not canonical)?
- Passing variables through permalink structure
- htaccess or redirect to cloak portion of a link?
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Using WP rather than .htaccess to redirect pages/posts
- .htaccess – Redirect duplicated post ended in ‘-number/’ to the same url without the -number/
- WordPress redirection problem after moving to a new server?
- Specific URL Rewriting with parameters in wordpress
- Redirect Loop to Page, Can’t Find Origin, Can’t Remove [closed]
- Which is better: 301 Redirect in my .htaccess file or a plugin like Redirection?
- If I change permalink structures, can I use htaccess to permanantly redirect links?
- Redirect parent taxonomy to it’s child
- Changed permalink structure. Need help with redirecting old posts
- Need Help Correct Regular Expression Redirect Code
- Plain permalinks not working!
- Custom Permalink
- Redirect an old link to new site homepage [closed]
- where to add redirection rewriterule in .htaccess file?
- Redirect a Blogger Page URL to wordpress
- How do I apply friendly URL permalinks to a custom WordPress template?
- Redirecting all posts after changing URL structure with htaccess
- Redirect all posts permalinks from “.html” to “/”
- WordPress 4.4 old permalink redirect
- Htaccess https 301 problem
- How do I setup htaccess for 301 redirects, post Joomla to WordPress migration? [closed]
- How to use different domains for different blogs hosted in the same host in subdomains with .htaccess
- What causes /pages/ to appear in URI, and how to remove it?
- Some Pemalink problems, probably caused by wrong .htaccess configuration?
- Test site pages go to main site
- Comment author url link is wrong? How to change from authors/ to author/
- Redirect wrong links WordPress
- change WordPress permalinks and redirect new urls 301
- Custom permalink structure with %postname% in front of domain name
- Configuring Home Page Address
- What’s the best way to manage a lot of 301 redirects in WordPress?
- WordPress Category url redirects to subdomain
- redirect 301 with special character like WIX site “#!”
- Can’t access WordPress site in subfolder possibly because of .htaccess redirect from root installation?
- different CNAME to corresponding subfolders
- Redirect from domain.com to subdomain.domain.com
- Removed and Reinstalled WordPress, Redirect Broken now
- redirect old pages by .htaccess
- Why are all pages redirecting to homepage when using custom permalinks?
- .htaccess regex for redirect subdomain to root domain & redirect old permalinks
- 404 posts error after 301 redirection of changed category / tag base
- 301 Redirect posts to newly added categories
- How to redirect all HTTP requests to HTTPS
- htaccess – Redirect to subfolder without changing browser URL
- Generic htaccess redirect www to non-www
- Redirect old php link to wordpress link in .htaccess
- Redirect old php link to wordpress link in .htaccess
- Safely redirect old WordPress blog links to new WP blog
- Double slashes on WordPress Admin URL redirects to wp-login
- 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
- Best collection of code for your .htaccess file [closed]
- Resolve a custom post type name vs. page permalink conflict (same slug)
- “Too many redirects” ONLY when trying to access wp-admin page
- Default .htaccess file for WordPress?
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- WordPress Redirect All HTTP requests to HTTPS via .htaccess
- Redirect entire website to a single page
- How does WordPress handle permalinks?
- Which one does WordPress prioritize when it comes to php.ini, wp-config and .htaccess?
- Improve wordpress security by hiding non public resources
- Use author author display name in permalink structure for pages and posts
- WordPress site hacked. Has .htaccess been hacked?
- Does this .htaccess security setting really work?
- Setting up WordPress with Custom Permalinks and no .htaccess File?
- Does WordPress Change the .htaccess File When Updating?
- Removing the redirect after changing a page’s slug
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Combining Multiple Taxonomies in one URL
- htaccess problem after saving Settings
- Move WordPress to subdirectory, keep ALL URLs
- File and directory permissions
- htaccess disable WordPress rewrite rules for folder and its contents
- htaccess rewrite conflict with wordpress rules and ssl
- WordPress Custom Post Type is Matching on Partial Slug
- How to remove category from wordpress url?
- Old blog/ and blog/feed/ URLs not working after moving blog to top-level via .htaccess
- How Do I Programmatically Force Custom Permalinks with My Theme?
- Non-WordPress page in subdirectory under WordPress page
- Permalinks to Custom does not work (out of box)
- URL rewrite based on a custom field value
- htaccess https redirect from www to non-www
- Force HTTPS using .htaccess – stuck in redirect loop
- WordPress permalinks Yahoo hosting(no .htaccess allowed)
- How can I force WordPress to redirect to canonical permalinks?
- PHP – redirect https to http and www to non-www
- Subdomains to pages
- Redirect old permalinks to new permalinks
- Permalink Issues by Installing WordPress in Subdirectory / Subfolder
- Htaccess for Wordpess set on single subdomain
- adding rewrite rules in .htaccess
- Redirecting WordPress /.htaccess / HSTS / SSL
- + Character in permalink
- 301 redirect not working through .htaccess