I want to add the following code to my htaccess but it does not work.

# ----------------------------------------------------------------------
# | Brotli pre-compressed content                                      |
# ----------------------------------------------------------------------

# Serve brotli compressed CSS, JS, HTML, SVG, ICS and JSON files
# if they exist and if the client accepts br encoding.
# (!) To make this part relevant, you need to generate encoded
# files by your own. Enabling this part will not auto-generate
# brotlied files.
# Note that some clients (eg. browsers) require a secure connection
# to request brotli-compressed resources.
# https://www.chromestatus.com/feature/5420797577396224
# https://httpd.apache.org/docs/current/mod/mod_brotli.html#precompressed

 <IfModule mod_headers.c>

     RewriteCond %{HTTP:Accept-Encoding} br
     RewriteCond %{REQUEST_FILENAME}\.br -f
     RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.br [L]

     # Prevent mod_deflate double gzip
     RewriteRule \.br$ - [E=no-gzip:1]

     <FilesMatch "\.br$">

         <IfModule mod_mime.c>
             # Serve correct content types
             AddType text/css              css.br
             AddType text/calendar         ics.br
             AddType text/javascript       js.br
             AddType application/json      json.br
             AddType text/html             html.br
             AddType image/svg+xml         svg.br

             # Serve correct content charset
             AddCharset utf-8 .css.br \
                              .ics.br \
                              .js.br \

         # Force proxies to cache brotlied and non-brotlied files separately
         Header append Vary Accept-Encoding


     # Serve correct encoding type
     AddEncoding br .br



Does not work in root and also not in pub.

  • 1
    it's commented out – Philipp Sander Feb 19 '19 at 10:50
  • Philipp is right, you have to uncomment it to make it work. – fmsthird Feb 19 '19 at 11:51
  • I know and I already did. Let me update the part ;-) I just forgot to update the part here in the question. The problem is that it does not do anything in the pub or the root .htaccess file. But when we open the br files directly in the browser we get the right encoding and output. It seems it has to do with the way Magento is loading static assets and how the rewrite works. – Daniel Ruf Feb 19 '19 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.