Set HTTP header for all PHP scripts via .htaccess file

11,747

Solution 1

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.

Solution 2

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>
Share:
11,747
yusufakyol
Author by

yusufakyol

I've been working as a programmer last 35 years. Programming is a hobby for me. I like too much to be busy with programming. Past 35 years, I worked as a programmer and also as a manager at many companies, especially at banks. At last I'm working as a freelancer adviser and programmer last years.

Updated on June 16, 2022

Comments

  • yusufakyol
    yusufakyol almost 2 years

    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