1

我正在尝试构建一个简单的 pastebin 应用程序,该应用程序直接通过 POST 接收内容,因此我可以使用 cURL(使用“-F”参数)通过终端上传文件。由于 Lighttpd (1.4) 正在生成“417 - 预期失败”错误并且不允许我使用 cURL,我正在尝试使用 PHP-FPM 在 nginx 上设置它。为了避免使用重写规则,我只是将每个 404 错误重定向到 'index.php' 来处理它们。但我无法正确设置状态码,我不明白为什么。这里有一些我正在尝试做的 PHP/伪代码:

header('Status: 200 OK'); // Change it to 200, as the request could came via a 404 error.
if (there_is_not_a_parameter_in_the_url()) {
    if (file_is_in_POST()) save_file();
    else {
        header('Status: 301 Moved Permanently');
        redirect_user_to_other_page(); // It's not possible to post a file from web, only directly by sending a POST request
    }
}
else {
    if (entry_does_not_exists()) {
        header('Status: 404 Not Found');
        show_404_page();
    }
    else show_entry();
}

调用该show_entry()函数时,状态码应该是200,因为它在开始时已更改。但我仍然得到一个404状态码。唯一正确更改它的时间是当我尝试将其设置为301, 在redirect_user_to_other_page()通话之前。

有人看到我做错了什么?

4

0 回答 0