Forum Moderators: coopster

Message Too Old, No Replies

Problem with header location

passing on the query string to new location

         

wildbest

6:39 am on Aug 5, 2010 (gmt 0)

10+ Year Member



<?php
// Request URI is [whatever.com?q=12345...]
header("Location: http://www.example.com/this.html");
?>

Server headers show new location is actually rewritten to "http://www.example.com/this.html/?q=12345" by the server. It's a shared hosting account at what it looks like IIS/PHP.

If new location is "http://www.example.com/" server location header is showing "http://www.example.com//?q=12345".

How do I stop server appending "/?q=12345" to new location URL?

lostdreamer

8:50 am on Aug 6, 2010 (gmt 0)

10+ Year Member



That shouldnt be happening, but you could try the following:
[script]
header("Location: http://www.example.com/this.html?");
[/script]
Notice the "?" on the end....


Regards,
LostDreamer

Matthew1980

9:27 am on Aug 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

Interesting..

There is something afoot here :) Is there anything preceding this header instruction? What are you actually trying to achieve with this redirect? Something spurious is getting into the mix somewhere, could you post some code to show its context please, then we can advise further.

Cheers,
MRb

wildbest

11:47 am on Aug 6, 2010 (gmt 0)

10+ Year Member



lostdreamer, with or without "?" it is still the same.

Matthew1980, this is the only code I have on this page:

<?php

$target = "http://www.example.com/this.html";

// Permanent redirection
header($_SERVER["SERVER_PROTOCOL"]." 301 Moved Permanently");
header("Status: 301 Moved Permanently");
header("Location: $target");
exit();

?>

Looking at "HTTP Live Headers" FF add-on server response is:

HTTP/1.1 301 Moved Permanently
Date: Fri, 06 Aug 2010 11:43:02 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Location: http://www.example.com/this.html/?q=12345
Cache-Control: private
Content-Length: 0

Without query string everything resolves correctly and no "/" is appended at the end of target url.