I have a plugin that sets up a custom rewrite rule. I can access the short URL and the content is returned correctly, but the HTTP response is 404, Page not found
.
From searching the web it seems like WordPress is returning 404, because it thinks this is not a valid WP page (http://wordpress.org/support/topic/404-on-custom-non-wordpress-pages).
Is there a recommended solution to this problem? How can I get WP to return a normal status code for a rewritten URL?
global $wp_rewrite;
add_rewrite_rule('list-data$',
'/wp-content/plugins/data-lister/list-data.php', 'top');
Thanks!
Mark
This has been an issue in core for a while, http://core.trac.wordpress.org/ticket/10722.
The simplest solution is to just overwrite the headers on ‘template_redirect’. You can replace them as long as you haven’t started any output yet, which you shouldn’t have at this point. Just call status_header( 200 );
No cache headers are also sent when the WP Class sends the 404 headers, so you’ll probably want to replace those with information based on the content you’re pulling from that PHP page.
Add this to functions.php:
I tried ‘template_redirect’ action (as @prettyboymp suggested) but it didn’t work.