Author Topic: Linux Apache .htaccess template to tweak performance on the web  (Read 2549 times)

0 Members and 1 Guest are viewing this topic.

inetbiz

  • eCommerce Strategy Consultant
  • Administrator
  • Full Member
  • *****
  • Offline Offline
  • Posts: 133
  • Karma: 22
  • SKYNET; T3; Apple Inc. Coincidence?
    • View Profile
    • Hosting for Creloaded Cart
Linux Apache .htaccess template to tweak performance on the web
« Reply #1 on: October 26, 2008, 04:14:40 PM »
You host must provide: mod_expires, mod_headers, mod_rewrite, .htaccess

Code: [Select]
# Remove -Multiviews if you show more than one character set
Options -Indexes -Multiviews

RewriteEngine on

# MJ12 Virus Bot
RewriteCond %{HTTP_USER_AGENT} ^MJ12bot/v1\.0\.8.*$
RewriteRule .* - [F]

RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

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

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A86400       
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A7257600
ExpiresByType text/css A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A604800
ExpiresByType application/x-shockwave-flash A604800
ExpiresByType video/x-flv A604800
ExpiresByType application/pdf A2419200
ExpiresByType text/html A600
</IfModule>

<IfModule mod_headers.c>
# 3 Month
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
    Header set Cache-Control "max-age=7257600"
    FileETag MTime Size
</FilesMatch>
# 1 Week
<FilesMatch "\.(js|css|pdf|txt)$">
    Header set Cache-Control "max-age=604800"
    FileETag MTime Size
</FilesMatch>
# 10 Minutes
<FilesMatch "\.(html|htm)$">
    Header set Cache-Control "max-age=600"
    FileETag MTime Size
</FilesMatch>
# NONE Dynamic Files shouldn't have as much browser header information. It decreases load time and file size
<FilesMatch "\.(pl|php|cgi|spl)$">
    Header unset Cache-Control
    Header unset Expires
    Header unset Last-Modified
    FileETag None
    Header unset Pragma
</FilesMatch>

# Hide .htaccess
<Files .htaccess>
order deny,allow
deny from all
</Files>

Adding this can bring your Yslow rating up from a D to a B More factors are explained within the Firefox plugin. Image file size can play a large factor in your Yslow grade.