.Htaccess-Fu

From Zoelife4U Wiki
(Redirected from Apache:.Htaccess-Fu)
Jump to: navigation, search

Mod Deflate for static content

Apache 2.2 Offers alot of major improvements over it's predecessors in many ways and one way is the way is handles gzip compression. Enter, mod_deflate a great piece of Apache module goodness that is easily applied to your website content. Below is an example to throw in .htaccess to compress Javascript and CSS files:

<IfModule mod_deflate.c>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

Block Access Based on Your Domain

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?alcohk.com$ [NC]
RewriteRule . - [F]

Various Caching Options

This looks like some fun things to put in .htaccess for caching purposes.

# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
 
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
 
# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"
</FilesMatch>
 
# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A7200
Header append Cache-Control "proxy-revalidate"
</FilesMatch>
 
# Force no caching for dynamic files
<FilesMatch "\.(php|cgi|pl|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
Personal tools
Online Users
Zoelife4U: