Posted By

andyr on 03/05/11


Tagged


Versions (?)

htaccess


 / Published in: Other
 

  1. # Apache configuration file
  2. # httpd.apache.org/docs/2.2/mod/quickreference.html
  3.  
  4. # Techniques in here adapted from all over, including:
  5. # Kroc Camen: camendesign.com/.htaccess
  6. # perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
  7.  
  8.  
  9. # Force the latest IE version, in various cases when it may fall back to IE7 mode
  10. # github.com/rails/rails/commit/123eb25#commitcomment-118920
  11. # Use ChromeFrame if it's installed for a better experience for the poor IE folk
  12. <IfModule mod_setenvif.c>
  13. <IfModule mod_headers.c>
  14. BrowserMatch MSIE ie
  15. Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  16. </IfModule>
  17. </IfModule>
  18.  
  19. <IfModule mod_headers.c>
  20. # Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
  21. # We need to inform proxies that content changes based on UA
  22. Header append Vary User-Agent
  23. # Cache control is set only if mod_headers is enabled, so that's unncessary to declare
  24. </IfModule>
  25.  
  26. # hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
  27. # Disabled. Uncomment to serve cross-domain ajax requests
  28. #<IfModule mod_headers.c>
  29. # Header set Access-Control-Allow-Origin "*"
  30. #</IfModule>
  31.  
  32.  
  33.  
  34.  
  35. # allow access from all domains for webfonts
  36. # alternatively you could only whitelist
  37. # your subdomains like "sub.domain.com"
  38.  
  39. <FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
  40. <IfModule mod_headers.c>
  41. Header set Access-Control-Allow-Origin "*"
  42. </IfModule>
  43. </FilesMatch>
  44.  
  45.  
  46. # video
  47. AddType video/ogg ogg ogv
  48. AddType video/mp4 mp4
  49. AddType video/webm webm
  50.  
  51. # Proper svg serving. Required for svg webfonts on iPad
  52. # twitter.com/FontSquirrel/status/14855840545
  53. AddType image/svg+xml svg svgz
  54. AddEncoding gzip svgz
  55.  
  56. # webfonts
  57. AddType application/vnd.ms-fontobject eot
  58. AddType font/truetype ttf
  59. AddType font/opentype otf
  60. AddType font/woff woff
  61.  
  62. # assorted types
  63. AddType image/vnd.microsoft.icon ico
  64. AddType image/webp webp
  65. AddType text/cache-manifest manifest
  66. AddType text/x-component htc
  67. AddType application/x-chrome-extension crx
  68.  
  69.  
  70.  
  71.  
  72. # allow concatenation from within specific js and css files
  73.  
  74. # e.g. Inside of script.combined.js you could have
  75. # <!--#include file="jquery-1.4.2.js" -->
  76. # <!--#include file="jquery.idletimer.js" -->
  77. # and they would be included into this single file
  78.  
  79. # this is not in use in the boilerplate as it stands. you may
  80. # choose to name your files in this way for this advantage
  81. # or concatenate and minify them manually.
  82. # Disabled by default.
  83.  
  84. # <FilesMatch "\.combined\.(js|css)$">
  85. # Options +Includes
  86. # SetOutputFilter INCLUDES
  87. # </FilesMatch>
  88.  
  89.  
  90.  
  91.  
  92.  
  93. # gzip compression.
  94. <IfModule mod_deflate.c>
  95.  
  96. # html, txt, css, js, json, xml, htc:
  97. AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
  98. AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
  99. AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
  100.  
  101. # webfonts and svg:
  102. <FilesMatch "\.(ttf|otf|eot|svg)$" >
  103. SetOutputFilter DEFLATE
  104. </FilesMatch>
  105. </IfModule>
  106.  
  107.  
  108.  
  109. # these are pretty far-future expires headers
  110. # they assume you control versioning with cachebusting query params like
  111. # <script src="application.js?20100608">
  112. # additionally, consider that outdated proxies may miscache
  113. # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
  114.  
  115. # if you don't use filenames to version, lower the css and js to something like
  116. # "access plus 1 week" or so
  117.  
  118. <IfModule mod_expires.c>
  119. Header set Cache-Control "public"
  120. ExpiresActive on
  121.  
  122. # Perhaps better to whitelist expires rules? Perhaps.
  123. ExpiresDefault "access plus 1 month"
  124.  
  125. # cache.manifest needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  126. ExpiresByType text/cache-manifest "access plus 0 seconds"
  127.  
  128. # your document html
  129. ExpiresByType text/html "access plus 0 seconds"
  130.  
  131. # data
  132. ExpiresByType text/xml "access plus 0 seconds"
  133. ExpiresByType application/xml "access plus 0 seconds"
  134. ExpiresByType application/json "access plus 0 seconds"
  135.  
  136.  
  137. # rss feed
  138. ExpiresByType application/rss+xml "access plus 1 hour"
  139.  
  140. # favicon (cannot be renamed)
  141. ExpiresByType image/vnd.microsoft.icon "access plus 1 week"
  142.  
  143. # media: images, video, audio
  144. ExpiresByType image/gif "access plus 1 month"
  145. ExpiresByType image/png "access plus 1 month"
  146. ExpiresByType image/jpg "access plus 1 month"
  147. ExpiresByType image/jpeg "access plus 1 month"
  148. ExpiresByType video/ogg "access plus 1 month"
  149. ExpiresByType audio/ogg "access plus 1 month"
  150. ExpiresByType video/mp4 "access plus 1 month"
  151. ExpiresByType video/webm "access plus 1 month"
  152.  
  153. # webfonts
  154. ExpiresByType font/truetype "access plus 1 month"
  155. ExpiresByType font/opentype "access plus 1 month"
  156. ExpiresByType font/woff "access plus 1 month"
  157. ExpiresByType image/svg+xml "access plus 1 month"
  158. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  159.  
  160. # css and javascript
  161. ExpiresByType text/css "access plus 1 month"
  162. ExpiresByType application/javascript "access plus 1 month"
  163. ExpiresByType text/javascript "access plus 1 month"
  164. </IfModule>
  165.  
  166.  
  167.  
  168.  
  169. # Since we're sending far-future expires, we don't need ETags for
  170. # static content.
  171. # developer.yahoo.com/performance/rules.html#etags
  172. FileETag None
  173.  
  174.  
  175.  
  176.  
  177. # Allow cookies to be set from iframes (for IE only)
  178. # If needed, uncomment and specify a path or regex in the Location directive
  179.  
  180. # <IfModule mod_headers.c>
  181. # <Location />
  182. # Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""
  183. # </Location>
  184. # </IfModule>
  185.  
  186.  
  187. # you probably want www.example.com to forward to example.com -- shorter URLs are sexier.
  188. # no-www.org/faq.php?q=class_b
  189. <IfModule mod_rewrite.c>
  190. RewriteEngine On
  191. RewriteCond %{HTTPS} !=on
  192. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  193. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  194. </IfModule>
  195.  
  196. # without -MultiViews, Apache will give a 404 for a rewrite if a folder of the same name does not exist
  197. # e.g. /blog/hello : webmasterworld.com/apache/3808792.htm
  198. Options -MultiViews
  199. # -Indexes will have Apache block users from browsing folders without a default document
  200. # Options -Indexes
  201.  
  202.  
  203.  
  204. # custom 404 page
  205. ErrorDocument 404 /404.html
  206.  
  207.  
  208.  
  209. # use utf-8 encoding for anything served text/plain or text/html
  210. AddDefaultCharset utf-8
  211. # force utf-8 for a number of file formats
  212. AddCharset utf-8 .html .css .js .xml .json .rss
  213.  
  214.  
  215.  
  216. # We don't need to tell everyone we're apache.
  217. ServerSignature Off
  218.  
  219.  
  220.  
  221.  

Report this snippet  

You need to login to post a comment.