views:

27

answers:

2

So I have a .htaccess file which is performing a rewrite from /testscript1.php/testvar1/testvar2 to /testscript2.php/testvar3/testvar4 (this is an over simplification but you get the idea).

Now though in my testscript2.php script when i access the $_SERVER['REQUEST_URI'] variable i see /testscript1.php/testvar1/testvar2 rather than /testscript2.php/testvar3/testvar4 which is what I am looking for. i.e $_SERVER['REQUEST_URI'] contains the uri before the rewrite.

My question is simply, is there a way to access the rewritten uri?

+2  A: 

Try using phpinfo() to get a view on what $_SERVER looks like on a rewritten page. Apache supplies quite a lot of info that may be useful.

On my test server, I get the following which may help you:

$_SERVER["REDIRECT_QUERY_STRING"]
$_SERVER["REDIRECT_URL"]
$_SERVER["QUERY_STRING"]
$_SERVER["REQUEST_URI"]
$_SERVER["SCRIPT_NAME"]
$_SERVER["PHP_SELF"]

I would expect that at least one or a combination of those should be able to reliably give you the information you're looking for.

Cheers.

Spudley
I had a look at phpinfo and turns out PATH_INFO has the information i need. Thanks a mil.
Andrew
A: 

If you’re using the path info to pass an additional path, you can strip that suffix from PHP_SELF:

substr(parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH), -strlen($_SERVER['PATH_INFO']))

Or simply use SCRIPT_NAME since PHP_SELF = SCRIPT_NAME + PATH_INFO. Just take a look at the various values in $_SEVER.

Gumbo