开发者

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: applicati开发者_如何学Con/xhtml+xml; charset=utf-8');
Header("Cache-Control: no-transform");

Thanks any help. Best regards.

Yusuf Akyol


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜