I am trying to send a request, but with some sites I always get a 301 Moved Permanently statue. Why it happens?

 telnet habrahabr.ru 80 GET / HTTP/1.1 Host: habrahabr.ru 

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of D-side , aleksandr barakin , user194374, cheops , pavel 14 aug '16 at 7:29 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Well answer, so what? Go where they ask. - D-side
  • one
    This is regular behavior in the framework of HTTP protocols, for some requests the server answers you with 301 HTTP code and redirects you to another URL. Please describe what difficulties you have. - cheops pm

2 answers 2

if you opened the browser console (and not telnet), the network tab, you would see that habrahabr.ru redirects to the https version of the site.

this is one of the reasons why the sites redirect, from others the site moves out of the domain and / or the domain is no longer used for http / https traffic, the crazy admin was unable to configure anything, etc. There may be many reasons, but the first (redirect from http to https) is the most common for large sites.

I doubt that you will be able to browse sites with only the https version through telnet, you need to be able to or VERY QUICKLY PRINT , or use something like curl / python / php / any other programming language / ... browser.

For those beginners who want to learn how the http protocol works (very simple) and how to debug it - I advise you to score on this matter and study the work of http2

  • If not difficult, can you develop your thought and show the nature of 3XX HTTP codes? What behavior is expected from HTTP 3XX codes? 302, 307? - cheops
  • Is it possible to learn more about "very fast typing"? - jisecayeyo
  • @jisecayeyo Well, in the https protocol, you have to read and send all sorts of key-certificates back and forth, it's not just "GET /", how would you send-receive them with your hands? - strangeqargo
  • @strangeqargo, but how can I try using telnet to try to connect to https ? - jisecayeyo
  • one
    telnet habrahabr.ru 443 (443 is the https port, browsers automatically access it when they see https in the link) - strangeqargo

This happens because the owners of the server want it so much. Code 301 means that the content has been moved and its new location is transferred in the Location parameter. The browser, having received the answer 301 should move to a new location.

It should be noted that 301 means not just "moved", but "moved forever." When re-requesting the original address, the browser may not even contact the server, but immediately request a document from the new location. There is code 302, which means "moved temporarily." This browser transition address is not necessary to remember.

  • How to send a request via telnet to the desired address, to give out status 200? - jisecayeyo
  • one
    @jisecayeyo Use address from Location . But in the case of Habr, you will not succeed - there is SSL, and you can’t do it in telnet . - user194374
  • @jisecayeyo it depends on the resource. If the server "wants" it can redirect you to 3XX-code for each request you receive. The code returned by the HTTP code is highly server dependent (you can make it so that you never get this code). - cheops