Apache mod rewrite returns blank screen for php files with wordpress header included

Here’s simplified .htaccess file:

RewriteEngine On

RewriteRule ^index$ index.php

On my local lamp server everything works fine, but there are some problems on production server. myurl/index returns only blank screen, php is not parsed. When required file is accessed directly (myurl/index.php) it works fine.

Read More

I noticed that this problem occurs only if in the required file the wordpress header is included (wp/wp-blog-header.php). After some more research I found out that blank screen is returned when wp() runs. Error reporting is enabled for wordpress and there are no entries in log files.

Does anybody have any idea why that happens?

Related posts

Leave a Reply

2 comments

  1. Thank you, Josh, for useful script.
    I found the solution. I don’t know why, but the content was buffered if rewritten url was used.

    <?php while (@ob_end_flush()); ?>
    

    in the beginning of the file helped.

  2. I know you said that error reporting is enabled but I figured I’d ask: how is it enabled? 99% of the times I’ve seen what you describe it’s because error reporting is disabled.

    Here’s a quick test to see if it is a PHP error. The following code will email you when a PHP error occurs. What I often do is place this into a file called “errorhandler.php” and include() that file in other PHP files to enable this error handler. You’ll need to tweak it to your scenario… E.G. change “YOURDOMAIN” and “YOUREMAIL” 🙂

    <?php
    
    function reportError($errorNumber, $errorString, $errorFile = false, $errorLine = false, $errorContext = false)
    {
        global $php_errormsg,$config,$system;
    
        $domainName = $_SERVER['HTTP_HOST'];
    
        $longDate = date("F j, Y g:i:s A O");
    
        $errorContext_ht = '<pre>'.htmlspecialchars(print_r($errorContext,true)).'</pre>';
    
        $backtrace = debug_backtrace();
    
        //$backtrace_ht = eval("return print_r($backtrace,true);");
        $backtrace_ht = '<pre>'.htmlspecialchars(print_r($backtrace,true)).'<pre>';
    
        $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    
        $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'N/A';
    
        $errorNumber_human = '';
    
        switch($errorNumber)
        {
            case E_ERROR:           $errorNumber_human = ' (E_ERROR)'; break;
            case E_NOTICE:          $errorNumber_human = ' (E_NOTICE)'; break;
            case E_WARNING:         $errorNumber_human = ' (E_WARNING)'; break;
            case E_PARSE:           $errorNumber_human = ' (E_PARSE)'; break;
            case E_CORE_ERROR:      $errorNumber_human = ' (E_CORE_ERROR)'; break;
            case E_CORE_WARNING:    $errorNumber_human = ' (E_CORE_WARNING)'; break;
            case E_COMPILE_ERROR:   $errorNumber_human = ' (E_COMPILE_ERROR)'; break;
            case E_COMPILE_WARNING: $errorNumber_human = ' (E_COMPILE_WARNING)'; break;
    
            case E_USER_ERROR:      $errorNumber_human = ' (E_USER_ERROR)'; break;
            case E_USER_WARNING:    $errorNumber_human = ' (E_USER_WARNING)'; break;
            case E_USER_NOTICE:     $errorNumber_human = ' (E_USER_NOTICE)'; break;
        }
    
        $error_env = compact('errorNumber', 'errorString', 'errorFile', 'errorLine', 'errorContext');
    
        $html = <<<END_OF_HTML_MESSAGE
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <style type="text/css">
    body {
    color: #000;
    background-color: #fff;
    font-family: Verdana, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    }
    </style>
    
    <body>
    <div id="content">
    <div id="header">
        <h1>Website Error Report</h1>
        <h2>{$domainName}</h2>
        <h3>{$longDate}</h2>
    </div>
    <div id="errorReport">
        <h2>Error Summary:</h2>
        <dl>
            <dt>Error Code</dt>
            <dd>{$errorNumber}{$errorNumber_human}</dd>
    
            <dt>Error String</dt>
            <dd>{$errorString}</dd>
    
            <dt>URL</dt>
            <dd><a href="{$url}">{$url}</a></dd>
    
            <dt>Error File</dt>
            <dd>{$errorFile} line {$errorLine}</dd>
    
            <dt>User Info</dt>
            <dd><a href="http://ws.arin.net/whosi/?queryinput={$_SERVER['REMOTE_ADDR']}">{$_SERVER['REMOTE_ADDR']}</a>
            using {$_SERVER['HTTP_USER_AGENT']}</dd>
    
            <dt>Referrer</dt>
            <dd><a href="{$referrer}">{$referrer}</a></dd>
    
            <dt>PHP Error Message</dt>
            <dd>{$php_errormsg}</dd>
    
            <dt>Context</dt>
            <dd>$errorContext_ht</dd>
    
            <dt>Backtrace</dt>
            <dd>$backtrace_ht</dd>
        </dl>
    </div>
    </div>
    </body>
    </body>
    </html>
    END_OF_HTML_MESSAGE;
    
    
        $subject = "{$domainName} Error!";
    
    
        $headers .="From: weberrors@YOURDOMAINHERErn";
        $headers .="Content-Type: text/html; charset="iso-8859-1"rn" .
                                    "Content-Transfer-Encoding: base64rnrn"; 
    
        mail('YOUREMAILHERE',$subject,chunk_split(base64_encode($html)),$headers);
    }
    
    function __error($errorNumber, $errorString, $errorFile = false, $errorLine = false, $errorContext = false)
    {
        $fatal = false;
        $msg = '';
    
        // #108 ignore IIS SSL errors
        if ($errorString == 'fgets(): SSL: fatal protocol error')
            return false;
    
        switch($errorNumber)
        {
            case E_NOTICE:
                // We don't care about notices or warnings. Pass off to PHP.
                return false;
    
    
            case E_USER_NOTICE:
                $msg = '';
                break;
    
            case E_USER_WARNING:
            case E_WARNING:
                $msg = <<< END_OF_HTML
    <p style="_errorWarning">There were potential errors processing your request. Our staff has been notified. 
    Please make sure your request was properly fulfilled. If you need assistance please contact us.</p>
    END_OF_HTML;
                break;
    
    
            case E_USER_ERROR:
            case E_CORE_ERROR:
            case E_ERROR: $fatal = true;
            default:
                $msg = <<< END_OF_HTML
    <h1>Error</h1>
    <h2>Your request could not be completed</h2>
    <p>We're sorry but your request could not be completed. We have automatically composed an error report
    which has been sent to the server administrator. Please try your request again, or email the staff and
    request assistance.</p>
    END_OF_HTML;
                break;
    
        }
    
        echo $msg;
    
        reportError($errorNumber, $errorString, $errorFile, $errorLine, $errorContext);
    
        if($fatal)
        {
            $obLevel = @ob_get_level();
    
            for($i=0;$i<$obLevel;$i++)
                ob_end_flush();
    
            exit();
        }
    
        return true;
    }
    
    
    set_error_handler('__error');