How Can A 301 Redirect Go To Different URLs?
Interesting case I came across yesterday. A URL which 301 redirected went to different URLs in different browsers.
First thought – the server was redirecting different UAs to different pages. But no, the redirect was exactly the same regardless of UA.
So how come different browsers ended up in different locations? In fact the Location was the problem:
HTTP/1.1 301·Moved·Permanently
Date:·Mon, 20 Jul 2009 16:33:14 GMT
Server: Microsoft-IIS/6.0
X-mhN: 4
X-Powered-By: ASP.NET
Location: http://www.example.com/pagename.html
Location: /
Content-Length: 0
Content-Type: text/html
Cache-control: private
The problem was that the redirect header had two Location attributes. Firefox 3.5 followed the last Location value, while Chrome followed the first. In 2 different browsers the client ended up in different locations.
The answer: Each redirect header should have only 1 Location attribute, and the value should be a fully formed URL (a value of “/” is technically incorrect).
Hopefully this might help someone else debug a redirect which sends different browsers to different pages/locations.
[...] Comments [...]
Pingback by Web Design and Development Tutorials - TheDevWeb.com — July 21, 2009 @ 3:21 pm
Interesting. I wonder which one Google, Bing and Yahoo decided to follow. It’s things that this that allow you to cloak the site in a not-too obvious way.
Not that I would ever condone such a thing!
Comment by Gregor — July 23, 2009 @ 4:29 pm