1

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.

5
  • 2
    How is your redirect relized? Commented Feb 22, 2011 at 17:57
  • 1
    Could you possibly rephrase this as an understandable question? I'd suggest reading Jon Skeet's 'Writing the Perfect Question' blog entry. Commented Feb 22, 2011 at 17:57
  • How are you redirecting? Is it a simple header("Location: index.php"); or are you using some sort of mod_rewrite (or some other option)? Commented Feb 22, 2011 at 17:58
  • Redirect happens with mod_rewrite? If so, take a look at $_SERVER['REQUEST_URI']. It may as well help to check print_r($_SERVER). Commented Feb 22, 2011 at 17:58
  • How does the redirect work? Is it a mod_rewrite, or a HTTP redirect (i.e. performed by the client), if the latter, you won't be able to get the previous URL (exception might be the referrer, but a client can disable that..) Commented Feb 22, 2011 at 17:59

2 Answers 2

1

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_start etc.).

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'].
Sign up to request clarification or add additional context in comments.

Comments

0

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

http://php.net/manual/en/reserved.variables.server.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.