.htaccess (Standard with Compression and Bad-Bot ReWrites)


/ Published in: PHP
Save to your folder(s)

This is a basic .htaccess file for Apache. I have commented off certain sections for Gzip and File Type Compression, Basic Template for ReWrites and Web Font control, plus Cache-Control.


Copy this code and paste it in your HTML
  1. # /.htacess
  2. # Last Updated on February 10, 2011
  3.  
  4. # BEGIN Basic Settings
  5. Options +execCGI +FollowSymLinks
  6. Options All -Indexes
  7.  
  8. ErrorDocument 404 /404.php
  9. ErrorDocument 401 /404.php
  10. ErrorDocument 403 /404.php
  11. ErrorDocument 500 /404.php
  12.  
  13. order allow,deny
  14. deny from 205.203.134.197
  15. deny from 109.230.246.24
  16. deny from 85.17.26.202
  17. deny from 85.17.26.196
  18. deny from 109.230.246.*
  19. allow from all
  20.  
  21. # Remove ETags
  22. FileETag None
  23.  
  24. # BEGIN GZip & Compression
  25. <IfModule mod_headers.c>
  26. <IfModule mod_mime.c>
  27. # Add custom mime type, to be able to use it in the 'AddOutputFilterByType' declaration (gzip font-face files: http://www.phpied.com/gzip-your-font-face-files/)
  28. AddType application/vnd.ms-fontobject .eot
  29. AddType font/truetype .ttf
  30. AddType font/opentype .otf
  31. AddType font/woff .woff
  32. # Proper svg serving. Required for svg webfonts on iPad (http://twitter.com/FontSquirrel/status/14855840545)
  33. AddType image/svg+xml svg svgz
  34. AddEncoding gzip svgz
  35. </IfModule>
  36.  
  37. # Apache 1.3 uses mod_gzip while Apache 2.x uses mod_deflate (http://httpd.apache.org/docs/2.0/mod/mod_deflate.html)
  38. <IfModule mod_deflate.c>
  39. # Enable the compression (gzip) for any type of content
  40. #SetOutputFilter DEFLATE
  41. # Or (alternatively) define which filetypes should pass through the DEFLATE output filter (gzip compression)
  42. AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json
  43. # html, xml, css, and js above, webfonts and svg below
  44. <FilesMatch "\.(ttf|otf|woff|eot|svg|svgz)$" >
  45. SetOutputFilter DEFLATE
  46. </FilesMatch>
  47.  
  48. # Turne-off (or restrict) compression to files of type text/html for known problematic web browsers
  49. BrowserMatch ^Mozilla/4 gzip-only-text/html
  50. BrowserMatch ^Mozilla/4\.0[678] no-gzip
  51. #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  52. # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  53. # the above regex won't work. You can use the following
  54. # workaround to get the desired effect:
  55. BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
  56.  
  57. # File types not to be compressed
  58. SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
  59. SetEnvIfNoCase Request_URI \.(?:swf|flv|pdf)$ no-gzip dont-vary
  60. SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
  61. SetEnvIfNoCase Request_URI \.(?:avi|mov)$ no-gzip dont-vary
  62. SetEnvIfNoCase Request_URI \.(?:mp3|mp4)$ no-gzip dont-vary
  63.  
  64. # Make sure proxies don't deliver the wrong content
  65. Header append Vary User-Agent env=!dont-vary
  66.  
  67. </IfModule>
  68. # Allow access from all domains for webfonts (alternatively you could only whitelist your subdomains like "sub.domain.com")
  69. <FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
  70. Header set Access-Control-Allow-Origin "*"
  71. </FilesMatch>
  72. </IfModule>
  73.  
  74. # BEGIN EXPIRES
  75. FileETag None
  76. <IfModule mod_expires.c>
  77. <FilesMatch "\.(gif|jpg|jpeg|png|swf|flv|pdf|ico|avi|mov|ppt|doc|mp3|wmv|wav|txt|css|js|html?|php|xml|eot|ttf|otf|woff)$">
  78. ExpiresActive On
  79. Header unset Last-Modified
  80. Header set Expires "Fri, 21 Dec 2013 00:00:00 GMT"
  81. Header set Cache-Control "public, no-transform"
  82. ExpiresDefault "access plus 1 year"
  83. FileETag Size
  84. </FilesMatch>
  85.  
  86. <FilesMatch "\.(gif|jpg|jpeg|png|swf|flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|txt|eot|ttf|otf|woff)$">
  87. Header append Cache-Control: public
  88. </FilesMatch>
  89. <FilesMatch "\.(css|js|html?|php|xml)$">
  90. Header append Cache-Control: private
  91. </FilesMatch>
  92. </IfModule>
  93.  
  94. # BEGIN CACHING
  95. <IfModule mod_expires.c>
  96. ExpiresActive On
  97. ExpiresDefault A86400
  98. ExpiresByType image/x-icon A2592000
  99. ExpiresByType application/x-javascript A2592000
  100. ExpiresByType text/css A2592000
  101. ExpiresByType image/gif A604800
  102. ExpiresByType image/png A604800
  103. ExpiresByType image/jpeg A604800
  104. ExpiresByType text/plain A604800
  105. ExpiresByType application/x-shockwave-flash A604800
  106. ExpiresByType video/x-flv A604800
  107. ExpiresByType application/pdf A604800
  108. ExpiresByType text/html A900
  109. </IfModule>
  110.  
  111. # 3 Month
  112. <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
  113. Header set Cache-Control "max-age=7257600"
  114. </FilesMatch>
  115. # 1 Week
  116. <FilesMatch "\.(js|css|pdf|txt)$">
  117. Header set Cache-Control "max-age=604800"
  118. </FilesMatch>
  119. # 10 Minutes
  120. <FilesMatch "\.(html|htm)$">
  121. Header set Cache-Control "max-age=600"
  122. </FilesMatch>
  123. # NONE
  124. <FilesMatch "\.(pl|php|cgi|spl)$">
  125. Header unset Cache-Control
  126. Header unset Expires
  127. Header unset Last-Modified
  128. FileETag None
  129. Header unset Pragma
  130. </FilesMatch>
  131.  
  132. # BEGIN Redirects from previous versions
  133. <IfModule mod_rewrite.c>
  134. RewriteEngine On
  135. RewriteBase /
  136. RewriteCond %{HTTP_USER_AGENT} ^(aesop_com_spiderman|alexibot|backweb|bandit|batchftp|bigfoot) [NC,OR]
  137. RewriteCond %{HTTP_USER_AGENT} ^(black.?hole|blackwidow|blowfish|botalot|buddy|builtbottough|bullseye) [NC,OR]
  138. RewriteCond %{HTTP_USER_AGENT} ^(cheesebot|cherrypicker|chinaclaw|collector|copier|copyrightcheck) [NC,OR]
  139. RewriteCond %{HTTP_USER_AGENT} ^(cosmos|crescent|curl|custo|da|diibot|disco|dittospyder|dragonfly) [NC,OR]
  140. RewriteCond %{HTTP_USER_AGENT} ^(drip|easydl|ebingbong|ecatch|eirgrabber|emailcollector|emailsiphon) [NC,OR]
  141. RewriteCond %{HTTP_USER_AGENT} ^(emailwolf|erocrawler|exabot|eyenetie|filehound|flashget|flunky) [NC,OR]
  142. RewriteCond %{HTTP_USER_AGENT} ^(frontpage|getright|getweb|go.?zilla|go-ahead-got-it|gotit|grabnet) [NC,OR]
  143. RewriteCond %{HTTP_USER_AGENT} ^(grafula|harvest|hloader|hmview|httplib|httrack|humanlinks|ilsebot) [NC,OR]
  144. RewriteCond %{HTTP_USER_AGENT} ^(infonavirobot|infotekies|intelliseek|interget|iria|jennybot|jetcar) [NC,OR]
  145. RewriteCond %{HTTP_USER_AGENT} ^(joc|justview|jyxobot|kenjin|keyword|larbin|leechftp|lexibot|lftp|libweb) [NC,OR]
  146. RewriteCond %{HTTP_USER_AGENT} ^(likse|linkscan|linkwalker|lnspiderguy|lwp|magnet|mag-net|markwatch) [NC,OR]
  147. RewriteCond %{HTTP_USER_AGENT} ^(mata.?hari|memo|microsoft.?url|midown.?tool|miixpc|mirror|missigua) [NC,OR]
  148. RewriteCond %{HTTP_USER_AGENT} ^(mister.?pix|moget|mozilla.?newt|nameprotect|navroad|backdoorbot|nearsite) [NC,OR]
  149. RewriteCond %{HTTP_USER_AGENT} ^(net.?vampire|netants|netcraft|netmechanic|netspider|nextgensearchbot) [NC,OR]
  150. RewriteCond %{HTTP_USER_AGENT} ^(attach|nicerspro|nimblecrawler|npbot|octopus|offline.?explorer) [NC,OR]
  151. RewriteCond %{HTTP_USER_AGENT} ^(offline.?navigator|openfind|outfoxbot|pagegrabber|papa|pavuk) [NC,OR]
  152. RewriteCond %{HTTP_USER_AGENT} ^(pcbrowser|php.?version.?tracker|pockey|propowerbot|prowebwalker) [NC,OR]
  153. RewriteCond %{HTTP_USER_AGENT} ^(psbot|pump|queryn|recorder|realdownload|reaper|reget|true_robot) [NC,OR]
  154. RewriteCond %{HTTP_USER_AGENT} ^(repomonkey|rma|internetseer|sitesnagger|siphon|slysearch|smartdownload) [NC,OR]
  155. RewriteCond %{HTTP_USER_AGENT} ^(snake|snapbot|snoopy|sogou|spacebison|spankbot|spanner|sqworm|superbot) [NC,OR]
  156. RewriteCond %{HTTP_USER_AGENT} ^(superhttp|surfbot|asterias|suzuran|szukacz|takeout|teleport) [NC,OR]
  157. RewriteCond %{HTTP_USER_AGENT} ^(telesoft|the.?intraformant|thenomad|tighttwatbot|titan|urldispatcher) [NC,OR]
  158. RewriteCond %{HTTP_USER_AGENT} ^(turingos|turnitinbot|urly.?warning|vacuum|vci|voideye|whacker) [NC,OR]
  159. RewriteCond %{HTTP_USER_AGENT} ^(libwww-perl|widow|wisenutbot|wwwoffle|xaldon|xenu|zeus|zyborg|anonymouse) [NC,OR]
  160. RewriteCond %{HTTP_USER_AGENT} ^web(zip|emaile|enhancer|fetch|go.?is|auto|bandit|clip|copier|master|reaper|sauger|site.?quester|whack) [NC,OR]
  161. RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
  162. RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
  163. RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
  164. RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
  165. RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
  166. RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
  167. RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
  168. RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
  169. RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
  170. RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
  171. RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
  172. RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
  173. RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
  174. RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
  175. RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
  176. RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
  177. RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
  178. RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
  179. RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
  180. RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
  181. RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
  182. RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
  183. RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
  184. RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
  185. RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
  186. RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
  187. RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
  188. RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
  189. RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
  190. RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
  191. RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
  192. RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
  193. RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
  194. RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
  195. RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
  196. RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
  197. RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
  198. RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
  199. RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
  200. RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
  201. RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
  202. RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
  203. RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
  204. RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
  205. RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
  206. RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
  207. RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
  208. RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
  209. RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
  210. RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
  211. RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
  212. RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
  213. RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
  214. RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
  215. RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
  216. RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
  217. RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
  218. RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
  219. RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
  220. RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
  221. RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
  222. RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
  223. RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
  224. RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
  225. RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
  226. RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
  227. RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
  228. RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
  229. RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
  230. RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
  231. RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
  232. RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
  233. RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
  234. RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
  235. RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
  236. RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
  237. RewriteCond %{HTTP_USER_AGENT} ^Zeus
  238. RewriteRule ^somedirectory/(.*)$ http://yourDomain.com/someFile.php [L,R=301]
  239. </IfModule>

URL: http://snipplr.com/view/48894/htaccess-standard-with-compression-and-badbot-rewrites/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.