Kevin Kevin - 2 months ago 12
HTTP Question

Check 301 http response with curl

I'm migrating a web site. And I need to do the migration of more than 600 old url to a new type of url
with symfony routing and 301 permanent redirection.

example of one of my url:

redirect_test-url:
path: /test-url
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /category/test-url
permanent: true


The redirect seems to work. But I need to be sure that all my old url are redirected with a 301 redirect.
I think I can do a script with php and curl to check all the url. But I don't know how can get the curl result.

Here is my curl request:

curl https://local.dev -k


But my terminal jut send me back html.

How can I get the http status code response to store it in a database?

Answer

You can dump the headers of the response with the -D option:

curl -s -D - http://www.martar.fr -o /dev/null

Response:

HTTP/1.1 301 Moved Permanently
Date: Fri, 07 Oct 2016 07:50:51 GMT
Server: Apache/2.4.10 (Debian)
Location: https://www.martar.fr/
Content-Length: 309
Content-Type: text/html; charset=iso-8859-1

-s is for Silent mode (don't output anything)