使用curl检查301 http响应

Kev*_*vin 3 php curl http symfony

我正在迁移一个网站。我需要将 600 多个旧 url 迁移到具有 symfony 路由和 301 永久重定向的新型 url。

我的网址之一的示例:

redirect_test-url:
    path: /test-url
    defaults:
        _controller: FrameworkBundle:Redirect:urlRedirect
        path: /category/test-url
        permanent: true 
Run Code Online (Sandbox Code Playgroud)

重定向似乎有效。但我需要确保我所有的旧网址都使用 301 重定向进行重定向。我想我可以用 php 和curl 编写一个脚本来检查所有的网址。但我不知道如何获得卷曲结果。

这是我的卷曲请求:

curl https://local.dev -k 
Run Code Online (Sandbox Code Playgroud)

但我的终端只是发回 html。

如何获取 http 状态代码响应并将其存储在数据库中?

Ham*_*bot 5

您可以使用以下选项转储响应的标头-D

curl -s -D - http://www.martar.fr -o /dev/null
Run Code Online (Sandbox Code Playgroud)

回复:

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
Run Code Online (Sandbox Code Playgroud)

-s用于静默模式(不输出任何内容)