Performance-wise .htaccess


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



Copy this code and paste it in your HTML
  1. ### Defaults
  2. AddDefaultCharset utf-8
  3. DefaultLanguage en-US
  4. ServerSignature Off
  5. Header unset ETag
  6. FileETag None
  7.  
  8. Options All -Indexes
  9. Options -MultiViews
  10. Options +FollowSymlinks
  11.  
  12.  
  13. ### Force the latest IE version
  14. <IfModule mod_headers.c>
  15. Header set X-UA-Compatible "IE=Edge,chrome=1"
  16. <FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|xpi|safariextz|vcf)$" >
  17. Header unset X-UA-Compatible
  18. </FilesMatch>
  19. </IfModule>
  20.  
  21.  
  22. <IfModule mod_headers.c>
  23. Header append Vary User-Agent
  24. </IfModule>
  25.  
  26.  
  27. ### Rewrites Engine
  28. <IfModule mod_rewrite.c>
  29. RewriteEngine On
  30. </IfModule>
  31.  
  32.  
  33. ### Redirects
  34.  
  35. # Redirect to non-WWW
  36. <IfModule mod_rewrite.c>
  37. RewriteCond %{HTTPS} !=on
  38. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  39. RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  40. </IfModule>
  41.  
  42. # Redirect to WWW
  43. #<IfModule mod_rewrite.c>
  44. #RewriteCond %{HTTPS} !=on
  45. #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  46. #RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  47. #</IfModule>
  48.  
  49.  
  50. ### Redirect Index to root
  51. RewriteCond %{QUERY_STRING} ^$
  52. RewriteRule ^index\.php$ / [R=301,L]
  53.  
  54.  
  55. ### Compression
  56. <IfModule mod_deflate.c>
  57.  
  58. <IfModule mod_setenvif.c>
  59. <IfModule mod_headers.c>
  60. SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  61. RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  62. </IfModule>
  63. </IfModule>
  64.  
  65. <IfModule filter_module>
  66. FilterDeclare COMPRESS
  67. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
  68. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
  69. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
  70. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
  71. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
  72. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
  73. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
  74. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
  75. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
  76. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
  77. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
  78. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
  79. FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
  80. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
  81. FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
  82. FilterChain COMPRESS
  83. FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
  84. </IfModule>
  85.  
  86. <IfModule !mod_filter.c>
  87. AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
  88. AddOutputFilterByType DEFLATE application/javascript
  89. AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
  90. AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
  91. AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
  92. </IfModule>
  93. </IfModule>
  94.  
  95.  
  96. ### Caching
  97. <IfModule mod_expires.c>
  98. ExpiresActive on
  99. ExpiresDefault "access plus 1 year"
  100.  
  101. ExpiresByType text/cache-manifest "access plus 0 seconds"
  102. ExpiresByType text/html "access plus 0 seconds"
  103. ExpiresByType text/xml "access plus 0 seconds"
  104. ExpiresByType application/xml "access plus 0 seconds"
  105. ExpiresByType application/json "access plus 0 seconds"
  106. ExpiresByType application/rss+xml "access plus 1 hour"
  107. ExpiresByType application/atom+xml "access plus 1 hour"
  108. ExpiresByType image/x-icon "access plus 1 year"
  109. ExpiresByType image/gif "access plus 1 year"
  110. ExpiresByType image/png "access plus 1 year"
  111. ExpiresByType image/jpg "access plus 1 year"
  112. ExpiresByType image/jpeg "access plus 1 year"
  113. ExpiresByType video/ogg "access plus 1 year"
  114. ExpiresByType audio/ogg "access plus 1 year"
  115. ExpiresByType video/mp4 "access plus 1 year"
  116. ExpiresByType video/webm "access plus 1 year"
  117. ExpiresByType text/x-component "access plus 1 year"
  118. ExpiresByType font/truetype "access plus 1 year"
  119. ExpiresByType font/opentype "access plus 1 year"
  120. ExpiresByType application/x-font-woff "access plus 1 year"
  121. ExpiresByType image/svg+xml "access plus 1 year"
  122. ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
  123. ExpiresByType text/css "access plus 1 year"
  124. ExpiresByType application/javascript "access plus 1 year"
  125.  
  126. <IfModule mod_headers.c>
  127. Header append Cache-Control "public"
  128. </IfModule>
  129. </IfModule>
  130.  
  131.  
  132. ### MIME Types
  133. AddType application/javascript js
  134. AddType audio/ogg oga ogg
  135. AddType audio/mp4 m4a
  136. AddType video/ogg ogv
  137. AddType video/mp4 mp4 m4v
  138. AddType video/webm webm
  139. AddType image/svg+xml svg svgz
  140. AddEncoding gzip svgz
  141. AddType application/vnd.ms-fontobject eot
  142. AddType application/x-font-ttf ttf ttc
  143. AddType font/opentype otf
  144. AddType application/x-font-woff woff
  145. AddType image/x-icon ico
  146. AddType image/webp webp
  147. AddType text/cache-manifest appcache manifest
  148. AddType text/x-component htc
  149. AddType application/x-chrome-extension crx
  150. AddType text/x-vcard vcf
  151.  
  152.  
  153. ### Limiting file upload size
  154. LimitRequestBody 10240000
  155.  
  156.  
  157. ### Increase cookie security
  158. <IfModule php5_module>
  159. php_value session.cookie_httponly true
  160. </IfModule>
  161.  
  162.  
  163. ### Deny access to sensitive files
  164. <FilesMatch "\.(htaccess|psd|log|ini)$">
  165. Order Allow,Deny
  166. Deny from all
  167. </FilesMatch>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.