简体   繁体   English

Apache不会为PHP脚本设置标头

[英]Apache won't set headers for PHP script

This .htaccess file: 这个.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>

... 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). ...在我的开发框(Windows框,Apache / 2.4.10,作为Apache模块运行的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. 但是,在我的生产服务器(Linux机箱,Apache / 2.2.31,运行为带有mod_fcgid / 2.3.9的FastCGI的PHP)中,它仅适用于静态资产,而不适用于PHP脚本。

Am I right suspecting that difference comes from the PHP SAPI? 我是否正确怀疑差异来自PHP SAPI? Is there a way to fix it so I don't need to duplicate the code that generates HTTP headers? 有没有办法解决它所以我不需要复制生成HTTP标头的代码?

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运行,则可能没有涉及文件系统目录,因此不会发生htaccess查找。

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. 现在有一个更新的php + mod_proxy_fcgi风格记录在使用SetHandler而不是ProxyPass的手册中 - 它允许处理像htaccess这样的事情,因为核心实际上是在文件系统中查找URL作为第一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM