gpt4 book ai didi

php - 使用 curl 检查 301 http 响应

转载 作者:可可西里 更新时间:2023-11-01 17:06:28 26 4
gpt4 key购买 nike

我正在迁移网站。我需要将 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 状态码响应并将其存储在数据库中?

最佳答案

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

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

关于php - 使用 curl 检查 301 http 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com