【问题标题】:Check 301 http response with curl使用 curl 检查 301 http 响应
【发布时间】:2016-10-07 07:12:12
【问题描述】:

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

我的网址之一的示例:

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

重定向似乎有效。但我需要确保我所有的旧网址都使用 301 重定向进行重定向。 我想我可以用 php 和 curl 做一个脚本来检查所有的 url。但是不知道怎么才能得到 curl 的结果。

这是我的 curl 请求:

curl https://local.dev -k 

但是我的终端将 html 发回给我。

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

【问题讨论】:

    标签: php symfony http curl


    【解决方案1】:

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

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

    回复:

    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 用于静音模式(不输出任何内容)

    【讨论】:

      【解决方案2】:

      我想也许你想要类似的东西:

      curl -sI https://example.com -w '%{response_code}:%{redirect_url}\n' -o /dev/null
      

      作为奖励,这将为您提供重定向代码和重定向目标(如果有)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-18
        • 2013-05-25
        • 2015-05-07
        • 1970-01-01
        • 2017-02-12
        • 1970-01-01
        相关资源
        最近更新 更多