Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set HTTP header for all PHP scripts via .htaccess file

I code same lines all PHP programs at one of my projects. Is it possible to do this at .htaccess for a directory? And how?

PHP codes:

Header('Content-Type: application/xhtml+xml; charset=utf-8');
Header("Cache-Control: no-transform");

Thanks any help. Best regards.

Yusuf Akyol

like image 764
yusufakyol Avatar asked Jan 26 '10 13:01

yusufakyol


2 Answers

If you want to do this with .htaccess (or in Apache config), you can use Apache module mod_headers, like this:

Header set Cache-Control "no-transform"
Header set Content-Type "application/xhtml+xml; charset=utf-8"

A search on htaccess set header gives you many more examples of this.

like image 131
Piskvor left the building Avatar answered Nov 10 '22 05:11

Piskvor left the building


For the content type you use AddType from mod_mime. Assuming all your files have .php extensions:

AddType application/xhtml+xml .php

Caching is set in mod_expires, but you need mod_headers to set Cache-Control:

<FilesMatch "\.php$">
    Header set Cache-Control "no-transform"
</FilesMatch>
like image 42
robertc Avatar answered Nov 10 '22 05:11

robertc