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

    Basics

    • My site is: https://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 https://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:

    https://mfields.org/portfolio/piece/66/extinction/

    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,
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Michael Fields

    (@mfields)

    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";
    	}
    	else
    		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.

    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.

    Thread Starter Michael Fields

    (@mfields)

    MECU, no problem, glad it worked for you ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘404 on custom ( non-wordpress ) pages’ is closed to new replies.