.htaccess examples

.htaccess examples for adding expiry headers, gzip compress, removing ETags etc…

#The top of your .htaccess file
RewriteEngine On
IndexIgnore *
Options +FollowSymLinks -Multiviews -Indexes
######################################################################
# Because some browsers won't really recognize fonts as legetimate files when comeing from CDN
AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf

	
		Header set Access-Control-Allow-Origin "*"
	

######################################################################

        # properly handle requests coming from behind proxies
        Header append Vary User-Agent
        
                Header append Vary Accept-Encoding
        

######################################################################
# Deflate files to fasten the loading with adding compression

	SetOutputFilter DEFLATE
	AddOutputFilterByType DEFLATE application/x-httpd-php text/html text/xml text/plain text/css text/javascript application/javascript application/x-javascript image/jpeg image/jpg image/png image/gif font/ttf font/eot font/otf


	# properly handle requests coming from behind proxies
	Header append Vary User-Agent
	# remove ETags, it's important
	Header unset ETag
	FileETag None
	Header unset Last-Modified


	#Setting expiry time by content type to 1 day
	ExpiresActive On
	ExpiresDefault "access plus 1 seconds"
	ExpiresByType image/gif "access plus 86400 seconds"
	ExpiresByType image/jpeg "access plus 86400 seconds"
	ExpiresByType image/png "access plus 86400 seconds"
	ExpiresByType text/css "access plus 86400 seconds"
	ExpiresByType text/javascript "access plus 86400 seconds"
	ExpiresByType application/x-javascript "access plus 86400 seconds"


	# Properly handle old browsers that do not support compression
	BrowserMatch ^Mozilla/4 gzip-only-text/html
	BrowserMatch ^Mozilla/4\.0[678] no-gzip
	BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
	# Explicitly exclude binary files from compression just in case
	SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|pdf|swf|ico|zip|ttf|eot|svg)$ no-gzip

######################################################################
# Protect your .htaccess file

        order allow,deny
        deny from all