Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am experimenting with the PHP redirect http://www.phpjunkyard.com/tutorials/php-redirect.php.

Specifically the 301 redirect to create a self correcting URL to help with typos - there's a unique ID in the URL as well that needs to be correct for it to work.

Can I still allow for analytics tracking parameters e.g. tracking=yes ?

Currently the rewrite strips this out.

share|improve this question
It's not mentioned in your linked article, but the header() function has a 3rd argument where you can specify the HTTP status code (ie. 301). See the PHP Docs: php.net/manual/en/function.header.php – w3dk Aug 14 '13 at 19:04

If you wanted to append all the query parameters you would want to use $_SERVER['QUERY_STRING'] to extract them from the current URL, you would then append this to the location of the redirect:

header("Location: http://www.New-Website.com?".$_SERVER['QUERY_STRING']);

If you only wanted to pass certain variables, you could get them individually and then append them in a similar way:

header("Location: http://www.New-Website.com?tracking=".$_GET["tracking"]);
share|improve this answer
Just to note, values in the $_GET array are already URL decoded. So these should be validated and possibly urlencode()d before building the URL. In fact it is advisable to validate everything you are 'passing back' to the URL. – w3dk Aug 14 '13 at 18:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.