【问题标题】:HTTP headers return 404 on non-www URL?HTTP标头在非www URL上返回404?
【发布时间】:2012-05-17 08:34:42
【问题描述】:

我正在服务器上的 mp3 文件上执行 PHP get_headers(),并在使用非 www 地址时接收 HTTP 404,在使用 www 时接收 HTTP 200。

我可以从浏览器中的任一地址访问该文件,那为什么是 404?我可以用 .htaccess 以某种方式解决这个问题吗?

1) WordPress 配置为使用非 www 地址 (example.com)

2) 文件位于 WordPress 安装的 wp-content/uploads 区域中

3) www 子域有一个 DNS CNAME 指向非 www 域 (www.example.com -> example.com)


标题:http://lhcsj.org/wp-content/uploads/2012/05/2012-5-6-sj.mp3

HTTP/1.1 404 Not Found
Date: Tue, 08 May 2012 21:11:43 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 314
Connection: close
Content-Type: text/html; charset=iso-8859-1

标题:http://www.lhcsj.org/wp-content/uploads/2012/05/2012-5-6-sj.mp3

HTTP/1.1 200 OK
Date: Tue, 08 May 2012 21:08:05 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Mon, 07 May 2012 17:19:47 GMT
ETag: "9c52430-e3626f-7a1332c0"
Accept-Ranges: bytes
Content-Length: 14901871
Connection: close
Content-Type: audio/mpeg

【问题讨论】:

  • 您在尝试访问您的 mp3 文件或页面时遇到了 HTTP 404?究竟是什么日志?
  • 好的,我已经添加了为每个文件 URL 返回的标题
  • 嗯,当我调用 get_headers('http://lhcsj.org/wp-content/uploads/2012/05/2012-5-6-sj.mp3') 时,我得到了 HTTP 200
  • @pier-alexandre-bouchar 我只是使用WordPress生成的默认htaccess:codex.wordpress.org/…
  • @anubhava 我想知道我在与文件相同的服务器上使用 get_headers() 是否会有所不同?

标签: wordpress http .htaccess dns http-status-code-404


【解决方案1】:

www.example.comexample.com 通过 DNS CNAME 条目指向同一个 IP 地址这一事实并不意味着服务器配置为同时为这两者提供服务。该服务器可以配置为处理大量 HTTP 主机,默认值可能不是www.example.com,而是其他东西。事实上,它会为未配置的主机(甚至不是默认主机)返回 404 状态,这并不奇怪。

检查www.example.comexample.com 的每个VirtualHost 条目是否存在于您的Apache Httpd 配置中。 Wordpress 是为特定主机配置的这一事实只有在通过该步骤后才会发挥作用。

【讨论】:

    猜你喜欢
    • 2017-08-29
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    相关资源
    最近更新 更多