I have url xyz.com/s2d3f4 which redirects to xyz.com/index.php.I want to capture s2d3f4.i have tried query string and it does not work .Any suggestions on how to get that value?I am using http redirect.
2 Answers
Every HTTP request is independent by design, so if you do a HTTP redirect (with header("Location: http://xyz.com/index.php") in PHP or RewriteRule ^ /index.php [R] in .htaccess) and the user sees http://xyz.com/index.php in the browser, then the original URL information is lost.
You can manually save it by
- adding it to the query string:
http://xyz.com/index.php?s=s2d3f4; - saving it in a session cookie (
session_startetc.).
On the other hand, if you are actually doing an internal redirect, so the user still sees http://xyz.com/s2d3f4 in the browser but it's handled by index.php, then
$_SERVER['REQUEST_URI']will hold the original URL (/s2d3f4);- you can also redirect with a query string (e.g.,
RewriteRule .* index.php?s=$0) and then that information will be available in$_REQUEST['s'].
Comments
Did you try PATH_INFO or 'ORIG_PATH_INFO
$HTTP_SERVER_VARS [deprecated] $_SERVER -- $HTTP_SERVER_VARS [deprecated] — Server and execution environment information
Anyway Try it
header("Location: index.php");or are you using some sort of mod_rewrite (or some other option)?$_SERVER['REQUEST_URI']. It may as well help to checkprint_r($_SERVER).