PHP ['SCRIPT_NAME'] Returning Empty String
I was working with Slim (v2.2.x) the other day and saw that a PHP warning was being thrown in one of the interal Slim files:
The code throwing the warning was the following if statement:
The actual issue was that
$_SERVER['SCRIPT_NAME'] was an empty string, so strpos was complaining as that is invalid syntax. Strangely, this was all working fine when we had the apache rewrite rules in an .htaccess file:
However once we moved the rules to the VirtualHost we got the warning. Some googling told me that this is a 6 year old problem with either apache, php, mod_php or the boogey man…depending on who you believe. It seems that various rewrite settings working differently if you have them in .htaccess vs the VirtualHost block.
I considered sending a pull request to Slim to handle the scenario where SCRIPT_NAME is empty:
But instead we added the PT (passthrough) rewrite flag. This works fine for what we’re doing and
$_SERVER['SCRIPT_NAME'] now returns /index.php as it should.