4

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.

  • 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 – MrWhite Aug 14 '13 at 19:04
4

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"]);
| improve this answer | |
  • 3
    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. – MrWhite Aug 14 '13 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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