Apache .htaccess and httpd.conf have the power to send and manipulate HTTP Header Requests and responses like sending P3P privacy headers, Content-Type: UTF-8, Content-Language: en-US, etc. The power is immense and you can do some really cool stuff with HTTP Headers!
Check out my advanced HTTP Header Viewer and Manipulator - Free Online Tool.
« For Webmasters | .htaccess Tutorial Index | » PHP htaccess tips
Custom HTTP Headers
Any time you see a meta tag of type "http-equiv" you can replace it with a real header in htaccess
- Prevent Caching 100%
- Remove IE imagetoolbar without meta tag
- Add Privacy (P3P) Header to your site
- Add a 'en-US' language header and 'UTF-8' without meta tags!
100% Prevent Files from being cached
This is similar to how google ads employ the header Cache-Control: private, x-gzip-ok="" to prevent caching of ads by proxies and clients.
<filesMatch ".(html|htm|js|css)$"> FileETag None <ifModule mod_headers.c> Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT" </ifModule> </FilesMatch>
Remove IE imagetoolbar
<filesMatch ".(html|htm)$"> <ifModule mod_headers.c> Header set imagetoolbar "no" </ifModule> </FilesMatch>
Add P3P Privacy Headers to your site
Adding a P3P header to your site is a good idea, do this.
<ifModule mod_headers.c> Header set P3P "policyref="/w3c/p3p.xml", CP="NOI DSP COR NID CUR ADM DEV OUR BUS"" # OR THIS, SIMPLER Header set P3P "policyref="/w3c/p3p.xml"" </ifModule>
Add a "en-US" language header and "UTF-8" without meta tags!
Article: Setting Charset in htaccess
AddDefaultCharset UTF-8 AddLanguage en-US .html .htm .css .js
Using AddType
AddType 'text/html; charset=UTF-8' .html
Using the Files Directive
Article: Using 'Files' in htaccess
<files ~ ".(htm|html|css|js)$"> AddDefaultCharset UTF-8 DefaultLanguage en-US </Files>
Using the FilesMatch Directive
Article: Using 'FilesMatch' in htaccess
<filesMatch ".(htm|html|css|js)$"> AddDefaultCharset UTF-8 DefaultLanguage en-US </FilesMatch>
htaccess Guide Sections
- htaccess tricks for Webmasters
- HTTP Header control with htaccess
- PHP on Apache tips and tricks
- SEO Redirects without mod_rewrite
- mod_rewrite examples, tips, and tricks
- HTTP Caching and Site Speedups
- Authentication on Apache
- htaccess Security Tricks and Tips
- SSL tips and examples
- Variable Fun (mod_env) Section
- .htaccess Security with MOD_SECURITY
- SetEnvIf and SetEnvIfNoCase Examples
« For Webmasters | .htaccess Tutorial Index | » PHP htaccess tips
April 10th, 2007
« htaccess Tricks for WebmastersPHP htaccess tips and tricks »
Comments Welcome
- karel
- http://www.galan.de Daniel
- http://www.ninjatactics.net/ johnny
- http://www.ninjatactics.net johnny
- http://brianswebdesign.com/ Brian’s Web Design
- Jackson
- Mike
- WiserX
- Tylan
- Tylan
- alexander
- ch
- mn
- Adam
- http://www.asipay.com Mitchel Carlsen
- http://www.e-sushi.net/ e-sushiâ„¢
- carla
- http://name.com User
- Mike