Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
    
Can't thank you enough for this. I was creating custom themes with an MVC framework bolt-on as well, and things worked in the browser, but not over AJAX or command line (with wget command test on Linux). Found I had to add "header('HTTP/1.1 200 OK');" in my index.php of the MVC framework in the theme in order to make it work. Glad that you knew about this bug or I'd be pretty frustrated for weeks! –  Volomike Dec 13 '11 at 6:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.