Senin, 13 Februari 2012

.htaccess tricks to speed up

Paste all this code into .htaccess file for Apache Based Web Servers. :)


<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /
#
#  Full path to your site
#
RewriteBase /
# Rename Photo Names
# RewriteRule ^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)\-(.*?)([_0-9]*?)\.(.*)$ file/pic/photo/$1/$2/$3$5.$6
#
#  Rules
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=/$1
 
# Image Access Protection
# RewriteRule ^file/pic/photo/(.*)\.(.*)$ static/image.php?file=$1&ext=$2</IfModule>
# Modify Headers<IfModule mod_headers.c>
# Cache files<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
  Header set Cache-Control "public"
  Header set Expires "Mon, 20 Apr 2015 20:00:00 GMT"
  Header unset Last-Modified</FilesMatch>
 
# Cache JavaScript & CSS<FilesMatch "\.(js|css)$">
  Header set Cache-Control "public"
  Header set Expires "Mon, 20 Apr 2015 20:00:00 GMT"
  Header unset Last-Modified</FilesMatch>
</IfModule>
 
# BEGIN GZIP<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE  text/html text/css text/plain image/svg+xml text/javascript text/xml application/x-javascript text/js image/jpg application/x-httpd-php application/xhtml+xml application/rss+xml application/javascript application/x-httpd-fastphp application/json</ifmodule>
# END GZIPAddHandler mode-deflate mod_deflate
 
# @todo This may not be effective in some cases
Header unset Pragma
FileETag None
Header unset ETag
 
# BEGIN Cache-Control Headers<ifModule mod_headers.c>
# 1 YEAR<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"</FilesMatch>
# 1 YEAR<FilesMatch "\.(css|js|php)$">
Header set Cache-Control "max-age=29030400, proxy-revalidate"</FilesMatch>
# 3 MONTH<FilesMatch "\.(gif|jpg|png|swf)$">
Header set Cache-Control "max-age=7257600, public"</FilesMatch>
# 2 DAYS<FilesMatch "\.(xml|txt)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"</FilesMatch>
# 1 MIN<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"</FilesMatch>
</ifModule>
# END Cache-Control Headers
 
AddHandler application/x-httpd-php .css
 
# Pass the default character set
AddDefaultCharset utf-8

Tidak ada komentar:

Posting Komentar

Tags

Blog Archive