Posted By

LuckyShot on 10/11/09


Tagged

modrewrite htaccess apache cache indexing 404 500 403


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
wirenaught


Apache .htaccess example


 / Published in: Apache
 

Disable directory indexing, custom error messages, PHP processing in other files, mod_rewrite, file GZIP and cache expiration times.

  1. ## Disable directory browsing
  2. Options All -Indexes
  3.  
  4.  
  5. ## Custom error messages (forbidden, notfound, servererror)
  6. ErrorDocument 403 /error.php?n=403
  7. ErrorDocument 404 /error.php?n=404
  8. ErrorDocument 500 /error.php?n=500
  9.  
  10.  
  11. ## If you need to process CSS files as PHP
  12. ## AddType application/x-httpd-php .css
  13.  
  14.  
  15.  
  16. ## Compress all text, html, javascript and css:
  17. AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-javascript application/javascript text/css
  18.  
  19.  
  20. ## Rewrite
  21. RewriteEngine on
  22. RewriteRule ^search/([a-zA-Z0-9]*)/(.*^&)$ ?q=$2&se=$1 [nc]
  23. RewriteRule ^info$ ?page=info [nc]
  24. RewriteRule ^type/([a-zA-Z0-9]*)$ ?t=$1 [nc]
  25. RewriteRule ^limit/([0-9]*)$ ?l=$1 [nc]
  26. RewriteRule ^go/([a-zA-Z0-9]*)$ ?go=$1 [nc]
  27.  
  28.  
  29. ## Cache Expiration times
  30.  
  31. # 1 YEAR
  32. <FilesMatch "\.(ico|flv)$">
  33. Header set Cache-Control "max-age=29030400, public"
  34. </FilesMatch>
  35.  
  36. # 1 MONTH
  37. <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
  38. Header set Cache-Control "max-age=2419200, public"
  39. </FilesMatch>
  40.  
  41. # 1 WEEK
  42. <FilesMatch "\.(doc|xls|ppt|pdf)$">
  43. Header set Cache-Control "max-age=604800, public"
  44. </FilesMatch>
  45.  
  46. # 2 DAYS
  47. #<FilesMatch "\.(xml|txt|css|js)$">
  48. #Header set Cache-Control "max-age=172800, proxy-revalidate"
  49. #</FilesMatch>
  50.  
  51. # 1 MIN
  52. #<FilesMatch "\.(html|htm|php)$">
  53. #Header set Cache-Control "max-age=60, private, proxy-revalidate"
  54. #</FilesMatch>

Report this snippet  

You need to login to post a comment.