Apache 不会为 PHP 脚本设置标头 [英] Apache won't set headers for PHP script

查看:35
本文介绍了Apache 不会为 PHP 脚本设置标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个.htaccess文件:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 4 month"
</IfModule>
<IfModule mod_headers.c>
    Header merge X-ModHeaders "Yes, it is installed"
</IfModule>

... 在我的开发箱(Windows 箱、Apache/2.4.10、PHP 作为 Apache 模块运行)中按预期工作,其中工作"意味着它为所有资源(静态或动态)生成适当的标头.

... works as expected in my development box (Windows box, Apache/2.4.10, PHP running as Apache module), where "works" means that it generates the appropriates headers for all resources (static or dynamic).

但是,在我的生产服务器(Linux 机器,Apache/2.2.31,PHP 以 FastCGI 和 mod_fcgid/2.3.9 运行)中,它仅适用于静态资产,不适用于 PHP 脚本.

However, in my production server (Linux box, Apache/2.2.31, PHP running as FastCGI with mod_fcgid/2.3.9) it only works for static assets, not for PHP scripts.

我怀疑差异来自 PHP SAPI 是否正确?有没有办法修复它,这样我就不需要复制生成 HTTP 标头的代码?

Am I right suspecting that difference comes from the PHP SAPI? Is there a way to fix it so I don't need to duplicate the code that generates HTTP headers?

推荐答案

如果 PHP 通过 mod_proxy_fcgi 运行,则可能不涉及文件系统目录,因此不会发生 htaccess 查找.

If PHP is running via mod_proxy_fcgi there might be no filesystem directory involved, hence no htaccess lookup can occur.

现在手册中记录了一种更新的 php+mod_proxy_fcgi 风格,它使用 SetHandler 而不是 ProxyPass —— 允许处理 htaccess 之类的事情,因为核心实际上在文件系统中查找 URL 作为第一步.

There is a more recent flavor of php+mod_proxy_fcgi now documented in the manual that uses SetHandler instead of ProxyPass -- that allows things like htaccess to be processed because the core actually looks up the URL in the filesystem as a first step.

这篇关于Apache 不会为 PHP 脚本设置标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆