After moving my website to a webhost using LiteSpeed, PHP headers appear to be ignored. I've tried setting custom headers in several ways:
$s = "HTTP/1.1 404 Not Found";
$s = "HTTP/1.0 404 Not Found";
$s = "Status: 404 Not Found";
$s = $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found';
followed by:
header($s)
However, none of these seem to work on LiteSpeed.
Questions:
- Is there a setting in LiteSpeed I can disable to get Apache-compatible header behavior? I have access to cPanel and
.htaccess.
- Are there any other possible explanations or solutions?
Notes:
- This issue occurs on both HTTPS and HTTP variations.
- The 404 page handles mod_rewrite (for URLs with no matching database content, a 404 response is expected).
- It also happens on another domain using a popular PHP forum solution with a mod_rewrite-based plugin for custom URLs.
- mod_rewrite itself works fine.
- The
header() call is also ignored on non-mod_rewrite URLs (e.g., test?id=2).
- Both sites work fine on traditional Apache hosts (at least two different Apache webhosts + localhost).
I've also disabled LiteSpeed caching in .htaccess:
<IfModule LiteSpeed>
RewriteRule .* - [E=Cache-Control:no-cache]
</IfModule>
To reproduce, create a simple test.php:
<?php
$s = $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found';
header($s);
echo 'test';
?>
Then try requesting test?id=2.
Source: Server Fault Archive (CC BY-SA 4.0)