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.

1
  • 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
    Commented Aug 14, 2013 at 19:04

1 Answer 1

5

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"]);
1
  • 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
    Commented Aug 14, 2013 at 18:45

Your Answer

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

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