Kevin Kevin - 18 days ago 7x
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:

path: /test-url
_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 -k

But my terminal jut send me back html.

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


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

curl -s -D - -o /dev/null


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

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