Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 –  w3d Aug 14 '13 at 19:04
add comment

1 Answer 1

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
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. –  w3d Aug 14 '13 at 18:45
add comment

Your Answer

 
discard

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.