ComputrScientist
ComputrScientist

Reputation: 152

`$_SERVER['SCRIPT_NAME']` includes REST resource instead of just the php file

Consider the following GET request: www.foo.com/bar.php/rest/resource, then the following should be the case:

$_SERVER['SCRIPT_NAME'] === 'bar.php';

This is true in my local machine, as well in our dev server. But in our test server:

echo $_SERVER['SCRIPT_NAME']; // bar.php/rest/resource

which is wrong. I'm pretty sure that this is caused by some Apache configuration, since the test server's failure started happening when it was upgraded from Apache 2.2 to 2.4.7 (with added configuration for our organization). I read the Apache upgrade/release notes and can't seem to pin down what's up.

More Info: I've checked out PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI and it seems that my PHP_SELF and SCRIPT_NAME is switched.Instead of

[PHP_SELF] => /test.php/foo/bar [SCRIPT_NAME] => /test.php

I get

[PHP_SELF] => /test.php [SCRIPT_NAME] => /test.php/foo/bar

Upvotes: 0

Views: 157

Answers (1)

Ian
Ian

Reputation: 25336

SCRIPT_NAME is defined by the webserver (Apache, NGINX, etc). Depending on your server configuration, the value of SCRIPT_NAME will be different. You need to check the vhost configs on both machines and make sure they match.

Upvotes: 2

Related Questions