[resolved] 404 on custom ( non-wordpress ) pages (4 posts)

  1. Michael Fields
    Posted 7 years ago #

    Hi. I'm having a bit of a problem with my blog, please read below for details. Thanks for reading!!!


    • My site is: http://mfields.org/
    • WordPress is installed in webroot.
    • /portfolio/ is a physical directory with an index file which uses: require_once '../wp-blog-header.php'; to include WordPress temple + functions.

    Overview of Problem

    I have a custom application at http://mfields.org/portfolio/ which showcase my paintings and designs. when you visit the address, all works fine, but if you click on one of the thumbnails:


    You will notice the WordPress is serving a "404 Not Found" status code.

    I am using the following code in .htaccess before the WordPress generated code:

    RewriteRule ^portfolio/([0-9]+)/$ /portfolio/?p=$1 [QSA,L]
    RewriteRule ^portfolio/piece/(.*)/(.*)/ /portfolio/piece.php?p=$1 [QSA,L]
    RewriteRule ^portfolio/piece/(.*)/ /portfolio/piece.php?p=$1 [QSA,L]

    Does anyone know how to trick WordPress into serving up a 200 for a 'non-WordPress' resource? Or, perhaps a way to register my rewrite rules through actions/filters. I just need WordPress to understand that these rewritten urls are valid resources and not 404's

    All help is appreciated,

  2. Michael Fields
    Posted 7 years ago #

    OK... Figured this one out:

    add_filter( 'status_header', 'mf_hack_404', 10 );
    function mf_hack_404( $c ) {
    	if( defined( 'GALLERY_NAME' ) ) {
    		$header = '200';
    		$text = get_status_header_desc( $header );
    		$protocol = $_SERVER["SERVER_PROTOCOL"];
    		if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol )
    			$protocol = 'HTTP/1.0';
    		return "$protocol $header $text";
    		return $c;

    Please Note that GALLERY_NAME is a constant that is defined only in my custom "pages" if you need to use this solution, try setting a constant in your custom script that you can test against.

  3. MECU
    Posted 6 years ago #

    Thank you mfields, this worked great for me.

    To help someone else, this goes in the theme functions "functions.php" file.

    You can easily define a constant like:
    define('GALLERY_NAME', TRUE);

    in your custom php files. You should replace GALLERY_NAME as mfields suggested, and TRUE could be anything.

  4. Michael Fields
    Posted 6 years ago #

    MECU, no problem, glad it worked for you :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.