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
- WordPress Redirect All HTTP requests to HTTPS via .htaccess
- Setting up WordPress with Custom Permalinks and no .htaccess File?
- 301 redirect not working through .htaccess
- multisite htaccess 301 redirects
- 302 redirect instead of 301 after switch to HTTPS
- Create additional short URL with custom field and 301 redirect
- Stop redirecting to posts not in a category / duplicate slugs
- Temporary .htaccess blocking is disabling WP Crons from running?
- How to create a 301 redirect that doesn’t apply to subsites
- Why does chrome keep downloading a file instead of running the site?
- What’s the opposite of required valid user in .htaccess authentication
- Https Redirect infinite loop in Mobile browsers
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- htaccess 301 Redirect not working for WordPress site
- 403 error on admin login page
- Change in permalink structure made javascript cookie not work correctly
- Change permalinks on move from one site to another
- How can I set Cache TTL for woff and woff2 font files with htaccess?
- How can I fix the redirect chain after implementing ssl on wordpress?
- How do I configure wordpress structure for development using git and composer
- How to – proper WordPress 301 redirects?
- Passing the JQuery string to Worldpress URL
- An other permalink problem – 404 Error
- Disable directory browsing of uploads folder
- add_rewrite_rule to remove /category/ from permalink
- Rewrite vs Redirect from ?p={ID}
- Force redirect single.php to index
- Issue redirecting ‘blog’ to ‘news’ in WordPress using .htaccess
- Use two different index pages
- Moving wordpress to different url/server creates redirect loop
- Redirect old query string URLs to new add_rewrite_rule URL
- 301 Rewriting htaccess
- Arabic permalink redirect to home page
- Temporary Infinite Redirect Loop
- How to execute WordPress as though it is in the root folder while it is installed in a subdirectory?
- Htaccess maintenance page rules that actually work with WordPress?
- How to allow only vpn access to dashboard on Bitnami WordPress by IP address restricting
- ErrorDocument 410 gives me back a 302 header
- How to create multiple Rewrite-Rule for various site in single htaccess?
- How do I skip wordpress’s 404 handling?
- Redirect to homepage if attmpting to leave intranet [closed]
- How to rewrite a folder in WordPress?
- Targeting .htaccess file with file_put_contents
- .htaccess file changes disappear
- Issue with permalinks for custom post type
- .htaccess and virtual host configuration for WP in its own directory
- 403 forbidden due to .htaccess?
- .htaccess not working in WordPress
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- htaccess strip url
- .htaccess seems to be required but I can not find it
- WordPress not remembering old slugs for pages