php redirect with HTTP query string variables

Simon Lenz picture Simon Lenz · Jan 15, 2011 · Viewed 84.8k times · Source

atm I'm using the following four lines to redirect the user to another page on my website:

<?php
    header("Status: 301 Moved Permanently");
    header("Location: ./content/index.html");
    exit;
?>

but there is a problem with the use of HTTP query string variables like http://< url >?param=blah
they don't get appended to url understandably.

Is there a smart move for implementing this?

greetings

Answer

regality picture regality · Jan 15, 2011
<?php
    header("Status: 301 Moved Permanently");
    header("Location:./content/index.html?". $_SERVER['QUERY_STRING']);
    exit;
?>