Use $_SERVER["REQUEST_URI"], as that reflects the same URI the client sees (so the address makes sense).
Personally, I'd use a regular expression to strip the parts out:
preg_match_all("/\\/([^\\/]+\\/U", $_SERVER["REQUEST_URI"], $m);
which would return an array of everything in slashes in the URI. You can then work with the array to figure the path out.