问题
This .htaccess
file:
<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).
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.
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?
回答1:
If PHP is running via mod_proxy_fcgi there might be no filesystem directory involved, hence no htaccess lookup can occur.
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.
来源:https://stackoverflow.com/questions/32147413/apache-wont-set-headers-for-php-script