Take the 2-minute tour ×

I'm writing a script which tries to access a web-page through HTTP. (The real page is not public, so I'll use an example page to explain my question.) For example, I'm trying to GET the page example.com/mypage. The server returns 301, and when I check the Location header I see it's value is... http://example.com/mypage - that is the EXACT same location I was trying to GET from the first place! How is my script supposed to get the page? Before seeing this I thought I should check the Location header and try to fetch it - but as it's the same location that would get me in an infinite loop!

Of course, when I try to browse the page with a browser I get the contents without a problem.

So my questions are:

1) What does it mean that the Location header matches the location I asked for perfectly with a 301 status?

2) How come the browser can display the page?

3) Is there any way to debug what goes on through the browser (e.g. to ask the browser for the response headers or something; asking for the page source is not enough, obviously).


share|improve this question
You can trace what goes in your browser by using your built-in browser debug tools (all browsers have such tools now, except maybe IE). –  Greg Hewgill Aug 5 '12 at 1:12
@Greg: thanks for your comment. I am using Firefox at the moment, and I've got FireBug installed. What can I do in order to monitor the responses and response headers the browser gets when I make a request? –  Tom Aug 5 '12 at 1:18
Chrome has a "Network" tab in the debug tools that shows every request and response with full headers. I am more familiar with Chrome than Firebug for that purpose, but I imagine Firebug has something similar. Looks like getfirebug.com/network might be what you need. –  Greg Hewgill Aug 5 '12 at 1:24
@Greg (and anyone): I've found the web console on Firefox which gives some information. It seems the browser gets a 200 in the first place, whereas my script gets a 301. Any ideas what might be causing this? (The page does not try to trick the client in any way. It's a standard WordPress page. A second page in a category listing.) –  Tom Aug 5 '12 at 2:15
Are you sure there isn't some different in the URL of the request and the Location: header of the response? Maybe a trailing slash? Also, did you actually send GET example.com/mypage? The hostname does not belong in the first line of the request. It only belongs in the Host: header. –  dsh Aug 5 '12 at 2:36

Your Answer



Browse other questions tagged or ask your own question.