Apache mod rewrite返回包含wordpress标头的php文件的空白屏幕

时间:2009-08-07 19:37:22

标签: php apache wordpress .htaccess mod-rewrite

这是简化的.htaccess文件:

RewriteEngine On

RewriteRule ^index$ index.php

在我的本地灯泡服务器上一切正常,但生产服务器上存在一些问题。 myurl / index只返回空白屏幕,不解析php。当直接访问所需文件(myurl / index.php)时,它可以正常工作。

我注意到只有在所需文件中包含wordpress标头(wp / wp-blog-header.php)才会出现此问题。经过一些研究后,我发现当wp()运行时会返回空白屏幕。为wordpress启用了错误报告,日志文件中没有条目。

有人知道为什么会这样吗?

2 个答案:

答案 0 :(得分:2)

谢谢你,Josh,有用的脚本。 我找到了解决方案。我不知道为什么,但如果使用重写的网址,内容会被缓冲。

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

在文件的开头帮助。

答案 1 :(得分:1)

我知道您说错误报告已启用,但我想我会问:它是如何启用的? 99%的时间我看到了你所描述的内容,因为错误报告已被禁用。

这是一个快速测试,看看它是否是PHP错误。发生PHP错误时,以下代码将通过电子邮件发送给您。我经常做的是将它放入一个名为“errorhandler.php”的文件中,并在其他PHP文件中包含()该文件以启用此错误处理程序。你需要将它调整到你的场景...... E.G.更改“YOURDOMAIN”和“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@YOURDOMAINHERE\r\n";
    $headers .="Content-Type: text/html; charset=\"iso-8859-1\"\r\n" .
                                "Content-Transfer-Encoding: base64\r\n\r\n"; 

    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');