>_ IzzyLab

Hands-on task

This task is step 17 of the course “Networking and HTTP from the terminal”

Follow the redirect

easy~3 min

The service at http://localhost/old responds with a redirect to /new. Follow the redirect chain and save the final content (after the redirect) into /root/final.txt. In the Site tab click the /old link — the browser follows the redirect on its own, while curl stops at it by default.

What you'll practise:
  • curl
  • http redirects
  • location header
  • response codes
  • output redirection

Topic breakdown

An HTTP redirect is a server response with a 3xx-class status (for example 302) and a Location header pointing to where the client should go for the real content. By default curl shows this response as-is and does NOT follow it, so a request to an intermediate address returns the empty redirect body instead of the final page. To make the client follow the whole chain to the final resource, curl has a dedicated follow-location flag. The resulting body is saved to a file with the > operator.

What's checked

  1. final.txt contains the final page

What it looks like