5

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?

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • PHP can edit headers but that doesn't mean it will by default. You should still get these at any rate – Machavity Aug 21 '15 at 18:59
  • 1
    Think the answer here applies: http://serverfault.com/questions/383011/mod-headers-not-sending-headers-when-file-is-php ... didn't dig in too deep but read those bug reports it references. – ficuscr Aug 21 '15 at 19:04
  • Is your production box on shared hosting? This might prevent you from changing certain apache modules... – Luc Laverdure Aug 21 '15 at 19:06
  • @ficuscr That's certainly my problem but the only answer so far claims it isn't a bug and links a ticket that talks about something else. Yuk.. – Álvaro González Aug 21 '15 at 19:50
  • @LucLaverdure - Yes, it's shared hosting. What exactly would I be able to change if it was a dedicated server? – Álvaro González Aug 21 '15 at 19:51
  • You'd be able to change everything on dedicated, what shared hosting do you have? There might be solutions looking for something specific to this hosting provider – Luc Laverdure Aug 21 '15 at 20:03
  • Maybe [`Header always merge X-ModHeaders "Yes, it is installed"`](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header)? – bishop Aug 21 '15 at 20:20
  • @bishop Sorry, I've tried all variations and it doesn't seem to be that. If the module generates any output, it's just wiped out. – Álvaro González Aug 22 '15 at 19:33

1 Answers1

4

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.

covener
  • 17,402
  • 2
  • 31
  • 45
  • Server is using "mod_fcgid/2.3.9" and `.htaccess` is certainly executed since other modules work as expected (e.g. `mod_rewrite` or the `AddHandler` directive to select the PHP version) and invalid directives cause a Status 500 response. – Álvaro González Aug 22 '15 at 19:30
  • BTW, I've updated the question with the actual CGI handler I'm using (it wasn't mod_fastcgi but mod_fcgid, my bad) – Álvaro González Aug 22 '15 at 19:44
  • For me this was the reason: I switched to the PHP Module on my shared hoster, and then `Header set` worked. – Andy Jul 24 '17 at 10:16
  • I eventually got confirmation from HSP support than their mod_fcgid setup prevented custom headers set in .htaccess from working. (I'm terribly sorry for not reporting back at the time!) – Álvaro González Mar 30 '18 at 17:55
  • @ÁlvaroGonzález do you have more information on this please? You know what exactly they've fixed? I am having the exact same problem... – Adrian Föder Nov 14 '18 at 09:17
  • 1
    @AdrianFöder They haven't fixed anything as far as I know. My hosting provider's specific set up does not allow those directives to have effect on the files they process. But since the problem only affects PHP files it's trivial to write a PHP workaround using `header()`. – Álvaro González Nov 14 '18 at 09:22