# #
# !! Notice !!
#
# Any changes to the .htaccess should be manually added to the .htaccess on
# the server. This file won't be updated with a new deploy.
# #

# Custom rewrites
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Require https
    RewriteCond %{HTTPS} !on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTP:CLOUDFRONT-FORWARDED-PROTO} !https [NC]
    RewriteCond %{HTTP_HOST} ^domain\.com$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
</IfModule>

# Hide sensitive files
<FilesMatch "\.(htaccess|htpasswd|ini|log|yml|sh|inc|bak)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Block all WordPress xmlrpc.php requests
<Files xmlrpc.php>
    order deny,allow
    deny from all
</Files>

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# Proper MIME types
<IfModule mod_mime.c>
    # Audio
    AddType audio/mp4                                   m4a f4a f4b
    AddType audio/ogg                                   oga ogg

    # JavaScript
    # Normalize to standard type (it's sniffed in IE anyways):
    # http://tools.ietf.org/html/rfc4329#section-7.2
    AddType application/javascript                      js
    AddType application/json                            json

    # Video
    AddType video/mp4                                   mp4 m4v f4v f4p
    AddType video/ogg                                   ogv
    AddType video/webm                                  webm

    # Web fonts
    AddType application/x-font-woff                     woff
    AddType application/font-woff2                      woff2

    # Browsers usually ignore the font MIME types and sniff the content,
    # however, Chrome shows a warning if other MIME types are used for the
    # following fonts.
    AddType application/x-font-ttf                      ttc ttf
    AddType font/opentype                               otf

    # Make SVGZ fonts work on iPad:
    # https://twitter.com/FontSquirrel/status/14855840545
    AddType     image/svg+xml                           svg svgz
    AddEncoding gzip                                    svgz

    # Other
    AddType application/octet-stream                    safariextz
    AddType application/x-chrome-extension              crx
    AddType application/x-opera-extension               oex
    AddType application/x-web-app-manifest+json         webapp
    AddType application/x-xpinstall                     xpi
    AddType application/xml                             atom rdf rss xml
    AddType image/webp                                  webp
    AddType image/x-icon                                ico
    AddType text/cache-manifest                         appcache manifest
    AddType text/vtt                                    vtt
    AddType text/x-component                            htc
    AddType text/x-vcard                                vcf
</IfModule>

# Cache rules
<IfModule mod_expires.c>
    ExpiresActive on

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

    # Favicon
    ExpiresByType image/x-icon              "access plus 1 day"

    # 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 application/font-woff2    "access plus 1 month"

    # CSS and JavaScript
    ExpiresByType text/css                  "access plus 1 month"
    ExpiresByType application/javascript    "access plus 1 month"
    ExpiresByType text/javascript           "access plus 1 month"
    ExpiresByType application/x-javascript  "access plus 1 month"

    # HTML and XML
    ExpiresByType application/xhtml+xml     "access plus 300 seconds"
    ExpiresByType text/html                 "access plus 300 seconds"
    ExpiresByType application/xml           "access plus 300 seconds"

    # Media
    ExpiresByType audio/ogg                 "access plus 1 month"
    ExpiresByType image/bmp                 "access plus 1 month"
    ExpiresByType image/gif                 "access plus 1 month"
    ExpiresByType image/jpeg                "access plus 1 month"
    ExpiresByType image/png                 "access plus 1 month"
    ExpiresByType image/svg+xml             "access plus 1 month"
    ExpiresByType image/webp                "access plus 1 month"
    ExpiresByType video/mp4                 "access plus 1 month"
    ExpiresByType video/ogg                 "access plus 1 month"
    ExpiresByType video/webm                "access plus 1 month"

    <IfModule mod_headers.c>
        Header append Cache-Control "public"
    </IfModule>
</IfModule>

<IfModule mod_deflate.c>
    # Compress text, html, javascript, css, xml, svg:
    AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript image/svg+xml application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
</IfModule>
