First of all, you need to get the full URL, for example, for my local server:
http://localhost/server_var.php?foo=bar&second=something
Try printing the $_SERVER with print_r() :
print_r( $_SERVER);
You should get the result as follows:
Array ( ... [REQUEST_URI] => /server_var.php?foo=bar&second=something ... )
Check out the man page for more information, so now you have your own url:
$url = 'http://www.mySecondSite.com' . $_SERVER['REQUEST_URI'];
And you can use header() to redirect your request:
header( 'Location: ' . $url);
I recommend taking a look at the HTTP status codes 3xx if you want to use 302 Found (default) or 307 Temporary Redirect ...
The second special case is the "Location:" header. Not only does this send this header back to the browser, but it will also return REDIRECT (302) for the browser if the status code 201 or 3xx is already set.
So you can do this:
header('HTTP/1.0 307 Temporary Redirect'); header( 'Location: ' . $url);
source share