Skip to content

Instantly share code, notes, and snippets.

@virtzilla
Forked from themorgantown/htaccess.txt
Created September 6, 2022 14:58
Show Gist options
  • Save virtzilla/e8cc0fb23e83c2f28fa403ec26d98a83 to your computer and use it in GitHub Desktop.
Save virtzilla/e8cc0fb23e83c2f28fa403ec26d98a83 to your computer and use it in GitHub Desktop.

Revisions

  1. @themorgantown themorgantown revised this gist Jan 28, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # File adapted from: https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

    # ------------------------------------------------------------------------------
    # | File Types |
    # ------------------------------------------------------------------------------
  2. @themorgantown themorgantown revised this gist Dec 18, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
    Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
    </IfModule>
    </IfModule>1

    # Files

    @@ -121,7 +121,7 @@
    ExpiresByType text/html "access plus 0 seconds"

    # JavaScript
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 hour"

    # Manifest files
    ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
  3. @themorgantown themorgantown revised this gist Aug 17, 2015. 1 changed file with 82 additions and 61 deletions.
    143 changes: 82 additions & 61 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # ------------------------------------------------------------------------------
    # | Web fonts access |
    # | File Types |
    # ------------------------------------------------------------------------------

    # Allow access from all domains for web fonts
    @@ -10,6 +10,86 @@
    </FilesMatch>
    </IfModule>

    # Files

    <IfModule mod_mime.c>

    # Data interchange

    AddType application/atom+xml atom
    AddType application/json json map topojson
    AddType application/ld+json jsonld
    AddType application/rss+xml rss
    AddType application/vnd.geo+json geojson
    AddType application/xml rdf xml


    # JavaScript

    # Normalize to standard type.
    # https://tools.ietf.org/html/rfc4329#section-7.2

    AddType application/javascript js


    # Manifest files

    AddType application/manifest+json webmanifest
    AddType application/x-web-app-manifest+json webapp
    AddType text/cache-manifest appcache


    # Media files

    AddType audio/mp4 f4a f4b m4a
    AddType audio/ogg oga ogg opus
    AddType image/bmp bmp
    AddType image/svg+xml svg svgz
    AddType image/webp webp
    AddType video/mp4 f4v f4p m4v mp4
    AddType video/ogg ogv
    AddType video/webm webm
    AddType video/x-flv flv

    # Serving `.ico` image files with a different media type
    # prevents Internet Explorer from displaying then as images:
    # https://github.com/h5bp/html5-boilerplate/commit/37b5fec090d00f38de64b591bcddcb205aadf8ee

    AddType image/x-icon cur ico


    # Web fonts

    AddType application/font-woff woff
    AddType application/font-woff2 woff2
    AddType application/vnd.ms-fontobject eot

    # Browsers usually ignore the font media types and simply sniff
    # the bytes to figure out the font type.
    # https://mimesniff.spec.whatwg.org/#matching-a-font-type-pattern
    #
    # However, Blink and WebKit based browsers will show a warning
    # in the console if the following font types are served with any
    # other media types.

    AddType application/x-font-ttf ttc ttf
    AddType font/opentype otf


    # Other

    AddType application/octet-stream safariextz
    AddType application/x-bb-appworld bbaw
    AddType application/x-chrome-extension crx
    AddType application/x-opera-extension oex
    AddType application/x-xpinstall xpi
    AddType text/vcard vcard vcf
    AddType text/vnd.rim.location.xloc xloc
    AddType text/vtt vtt
    AddType text/x-component htc

    </IfModule>

    # ------------------------------------------------------------------------------
    # | Expires headers (for better cache control) |
    # ------------------------------------------------------------------------------
    @@ -90,67 +170,8 @@
    </FilesMatch>
    </IfModule>

    # ##############################################################################
    # # MIME TYPES AND ENCODING #
    # ##############################################################################

    # ------------------------------------------------------------------------------
    # | Proper MIME types for all files |
    # ------------------------------------------------------------------------------

    <IfModule mod_mime.c>

    # Audio
    AddType audio/mp4 m4a f4a f4b
    AddType audio/ogg oga ogg
    AddType audio/mpeg mp3

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

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

    # Web fonts
    AddType application/font-woff woff
    AddType application/vnd.ms-fontobject eot

    # 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-shockwave-flash swf
    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>

    # ------------------------------------------------------------------------------
    # | Compression |
    # | Compression (Enables Gzip) |
    # ------------------------------------------------------------------------------

    <IfModule mod_deflate.c>
  4. @themorgantown themorgantown revised this gist May 19, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -103,6 +103,7 @@
    # Audio
    AddType audio/mp4 m4a f4a f4b
    AddType audio/ogg oga ogg
    AddType audio/mpeg mp3

    # JavaScript
    # Normalize to standard type (it's sniffed in IE anyways):
  5. @themorgantown themorgantown revised this gist Apr 11, 2013. 1 changed file with 186 additions and 103 deletions.
    289 changes: 186 additions & 103 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -1,107 +1,190 @@
    # This file needs to be renamed to .htaccess after uploading to your web server. If should be uploaded in the directory under which you'd like to affect your files.


    # ----------------------------------------------------------------------
    # Webfonts
    # ----------------------------------------------------------------------

    # allow access from all domains for webfonts
    # alternatively you could only whitelist
    # your subdomains like "sub.domain.com"

    <FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>

    # Webfont mime types
    AddType application/vnd.ms-fontobject eot
    AddType font/truetype ttf
    AddType font/opentype otf
    AddType application/x-font-woff woff

    # Webfonts and svg:
    <IfModule mod_deflate.c>
    <FilesMatch "\.(ttf|otf|eot|svg)$" >
    SetOutputFilter DEFLATE
    </FilesMatch>
    # ------------------------------------------------------------------------------
    # | Web fonts access |
    # ------------------------------------------------------------------------------

    # Allow access from all domains for web fonts

    <IfModule mod_headers.c>
    <FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
    Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
    </IfModule>

    # Video Support

    AddType video/ogg .ogv
    AddType audio/ogg .ogg
    AddType video/ogg .ogv
    AddType video/mp4 .mp4
    AddType video/webm .webm

    # ----------------------------------------------------------------------
    # Expires headers (for better cache control)
    # ----------------------------------------------------------------------

    #
    # These are pretty far-future expires headers
    # They assume you control versioning with cachebusting query params like:
    # <script src="application.js?20100608">
    # Additionally, consider that outdated proxies may miscache
    #
    # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

    #
    # If you don`t use filenames to version, lower the css and js to something like "access plus 1 week"
    #

    # ------------------------------------------------------------------------------
    # | Expires headers (for better cache control) |
    # ------------------------------------------------------------------------------

    # The following expires headers are set pretty far in the future. If you don't
    # control versioning with filename-based cache busting, consider lowering the
    # cache time for resources like CSS and JS to something like 1 week.

    <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 0 seconds"

    # 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 week"

    # 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 mod_headers.c>
    Header append Cache-Control "public"
    </IfModule>


    ExpiresActive on
    ExpiresDefault "access plus 1 month"

    # CSS
    ExpiresByType text/css "access plus 1 year"

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

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

    # HTML components (HTCs)
    ExpiresByType text/x-component "access plus 1 month"

    # HTML
    ExpiresByType text/html "access plus 0 seconds"

    # JavaScript
    ExpiresByType application/javascript "access plus 1 year"

    # Manifest files
    ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
    ExpiresByType text/cache-manifest "access plus 0 seconds"

    # Media
    ExpiresByType audio/ogg "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 video/mp4 "access plus 1 month"
    ExpiresByType video/ogg "access plus 1 month"
    ExpiresByType video/webm "access plus 1 month"

    # Web feeds
    ExpiresByType application/atom+xml "access plus 1 hour"
    ExpiresByType application/rss+xml "access plus 1 hour"

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

    </IfModule>

    # ##############################################################################
    # # INTERNET EXPLORER #
    # ##############################################################################

    # ------------------------------------------------------------------------------
    # | Better website experience |
    # ------------------------------------------------------------------------------

    # Force IE to render pages in the highest available mode in the various
    # cases when it may not: http://hsivonen.iki.fi/doctype/ie-mode.pdf.
    # Use, if installed, Google Chrome Frame.

    <IfModule mod_headers.c>
    Header set X-UA-Compatible "IE=edge,chrome=1"
    # `mod_headers` can't match based on the content-type, however, we only
    # want to send this header for HTML pages and not for the other resources
    <FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webapp|webm|webp|woff|xml|xpi)$">
    Header unset X-UA-Compatible
    </FilesMatch>
    </IfModule>

    # ##############################################################################
    # # MIME TYPES AND ENCODING #
    # ##############################################################################

    # ------------------------------------------------------------------------------
    # | Proper MIME types for all files |
    # ------------------------------------------------------------------------------

    <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 jsonp
    AddType application/json json

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

    # Web fonts
    AddType application/font-woff woff
    AddType application/vnd.ms-fontobject eot

    # 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-shockwave-flash swf
    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>

    # ------------------------------------------------------------------------------
    # | Compression |
    # ------------------------------------------------------------------------------

    <IfModule mod_deflate.c>

    # Force compression for mangled headers.
    # http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
    <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
    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>

    # Compress all output labeled with one of the following MIME-types
    # (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
    # and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
    # as `AddOutputFilterByType` is still in the core directives).
    <IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
    application/javascript \
    application/json \
    application/rss+xml \
    application/vnd.ms-fontobject \
    application/x-font-ttf \
    application/x-web-app-manifest+json \
    application/xhtml+xml \
    application/xml \
    font/opentype \
    image/svg+xml \
    image/x-icon \
    text/css \
    text/html \
    text/plain \
    text/x-component \
    text/xml
    </IfModule>

    </IfModule>
  6. @themorgantown themorgantown revised this gist Feb 12, 2013. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -15,13 +15,13 @@
    </IfModule>
    </FilesMatch>

    # webfont mime types
    AddType application/vnd.ms-fontobject eot
    AddType font/truetype ttf
    AddType font/opentype otf
    # Webfont mime types
    AddType application/vnd.ms-fontobject eot
    AddType font/truetype ttf
    AddType font/opentype otf
    AddType application/x-font-woff woff

    # webfonts and svg:
    # Webfonts and svg:
    <IfModule mod_deflate.c>
    <FilesMatch "\.(ttf|otf|eot|svg)$" >
    SetOutputFilter DEFLATE
    @@ -72,7 +72,7 @@ AddType video/webm .webm
    # RSS feed
    ExpiresByType application/rss+xml "access plus 1 hour"

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

    # Media: images, video, audio
  7. @themorgantown themorgantown revised this gist Feb 12, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,13 @@ AddType application/x-font-woff woff
    </FilesMatch>
    </IfModule>

    # Video Support

    AddType video/ogg .ogv
    AddType audio/ogg .ogg
    AddType video/ogg .ogv
    AddType video/mp4 .mp4
    AddType video/webm .webm

    # ----------------------------------------------------------------------
    # Expires headers (for better cache control)
  8. @themorgantown themorgantown created this gist Feb 12, 2013.
    100 changes: 100 additions & 0 deletions htaccess.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,100 @@
    # This file needs to be renamed to .htaccess after uploading to your web server. If should be uploaded in the directory under which you'd like to affect your files.


    # ----------------------------------------------------------------------
    # Webfonts
    # ----------------------------------------------------------------------

    # allow access from all domains for webfonts
    # alternatively you could only whitelist
    # your subdomains like "sub.domain.com"

    <FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>

    # webfont mime types
    AddType application/vnd.ms-fontobject eot
    AddType font/truetype ttf
    AddType font/opentype otf
    AddType application/x-font-woff woff

    # webfonts and svg:
    <IfModule mod_deflate.c>
    <FilesMatch "\.(ttf|otf|eot|svg)$" >
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>


    # ----------------------------------------------------------------------
    # Expires headers (for better cache control)
    # ----------------------------------------------------------------------

    #
    # These are pretty far-future expires headers
    # They assume you control versioning with cachebusting query params like:
    # <script src="application.js?20100608">
    # Additionally, consider that outdated proxies may miscache
    #
    # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/

    #
    # If you don`t use filenames to version, lower the css and js to something like "access plus 1 week"
    #

    <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 0 seconds"

    # 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 week"

    # 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 mod_headers.c>
    Header append Cache-Control "public"
    </IfModule>

    </IfModule>