RewriteEngine on
Options -Indexes +FollowSymLinks -MultiViews

AddType text/cache-manifest .manifest
AddDefaultCharset UTF-8

### OPTIONAL: htaccess-redirect-http
### BEGIN http-redirect
### END http-redirect

### OPTIONAL: htaccess-redirect-https
### BEGIN https-redirect
### END https-redirect

#css | js
RewriteCond   %{REQUEST_URI}                ^/assets
RewriteRule   ^assets/(.*)                   /cache/assets/$1 [L]

#media
RewriteCond   %{REQUEST_URI}                ^/media
RewriteRule   ^media/(.*)                   /cache/.thumbs/$1 [L]

### OPTIONAL: htaccess-cache
### BEGIN htaccess-cache
#css | js
RewriteCond   %{REQUEST_URI}                ^/assets
RewriteRule   ^assets/(.*)                   /cache/assets/$1 [L]

#media
RewriteCond   %{REQUEST_URI}                ^/media
RewriteRule   ^media/(.*)                   /cache/.thumbs/$1 [L]
### END htaccess-cache

<IfModule mod_rewrite.c>
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteRule ^(.*) /index.php [L,QSA]
</IfModule>

### REQUIRE: htaccess-security
### BEGIN htaccess-security
# RULES
<IfModule mod_deflate.c>
# force deflate for mangled headers
# developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIf Authorization .+ Authorization=$0
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>
  # Legacy versions of Apache
  AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
  AddOutputFilterByType DEFLATE application/javascript text/application
  AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
  AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject application/x-font-ttf font/opentype
  AddOutputFilterByType DEFLATE image/svg+xml image/png image/jpeg image/gif image/x-icon
</IfModule>
<IfModule mod_expires.c>
  ExpiresActive on

  # Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

  # cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"

  # Your document html
  ExpiresByType text/html                 "access plus 1 week"

  # Data
  ExpiresByType text/xml                  "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType application/json          "access plus 0 seconds"

  # RSS feed
  ExpiresByType application/rss+xml       "access plus 1 hour"

  # Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 month"

  # Media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType video/ogg                 "access plus 1 month"
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType video/mp4                 "access plus 1 month"
  ExpiresByType video/webm                "access plus 1 month"

  # HTC files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 month"

  # Webfonts
  ExpiresByType font/truetype             "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

  # CSS and JavaScript
  ExpiresByType text/css                  "access plus 1 year"
  ExpiresByType application/javascript    "access plus 1 year"
  ExpiresByType text/javascript           "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz|svg)$">
    Header set Cache-Control: public
  </FilesMatch>
  <FilesMatch "\.(html|js|css|xml|gz|svg)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>

# Since we`re sending far-future expires, we dont need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None
### END htaccess-security

### REQUIRE: htaccess-test
### BEGIN htaccess-test
### END htaccess-test

### OPTIONAL: htaccess-security-cors
### BEGIN security-cors
### END security-cors

### OPTIONAL: htaccess-security-x-frame-options
### BEGIN x-frame-options
### END x-frame-options

### OPTIONAL: htaccess-security-content-security-policy
### BEGIN security-policy
### END security-policy
