Skip to content

Instantly share code, notes, and snippets.

@DevPoint
Last active September 21, 2024 07:05
Show Gist options
  • Save DevPoint/76ff3fa41eab50ef07dda5611bf1ed83 to your computer and use it in GitHub Desktop.
Save DevPoint/76ff3fa41eab50ef07dda5611bf1ed83 to your computer and use it in GitHub Desktop.
Blazor WebAssembly App - htaccess für Apache
<IfModule mod_rewrite.c>
## Serve precompressed Brotli files if they exist.
## Adapted from <https://stackoverflow.com/questions/46487635/how-to-serve-precompressed-gzip-brotli-files-with-htaccess>
## Make sure `RewriteBase /` is present somewhere in your .htaccess file.
# If the web browser accepts Brotli encoding...
RewriteCond %{HTTP:Accept-encoding} br
# ...and the web browser is fetching a probably pre-compressed file...
RewriteCond %{REQUEST_URI} .*\.(css|dat|html|js|json|svg|wasm)
# ...and a matching pre-compressed file exists...
RewriteCond %{REQUEST_FILENAME}.br -s
# ...then rewrite the request to deliver the Brotli file.
RewriteRule ^(.+) $1.br
# For each file format set the correct MIME type. Otherwise, the Brotli mime type is returned.
# Also prevent Apache from recompressing the files.
RewriteRule "\.css\.br$" "-" [T=text/css,E=no-brotli,E=no-gzip]
RewriteRule "\.dat\.br$" "-" [T=application/octet-stream,E=no-brotli,E=no-gzip]
RewriteRule "\.html\.br$" "-" [T=text/html,E=no-brotli,E=no-gzip]
RewriteRule "\.js\.br$" "-" [T=application/javascript,E=no-brotli,E=no-gzip]
RewriteRule "\.json\.br$" "-" [T=application/json,E=no-brotli,E=no-gzip]
RewriteRule "\.svg\.br$" "-" [T=image/svg+xml,E=no-brotli,E=no-gzip]
RewriteRule "\.wasm\.br$" "-" [T=application/wasm,E=no-brotli,E=no-gzip]
<FilesMatch "\.(css|dat|html|js|json|svg|wasm)\.br$">
# Prevent mime module from setting Brazilian language header (because the file ends with .br).
RemoveLanguage .br
# Set the correct encoding type.
Header set Content-Encoding br
# Force proxies to cache Brotli and non-Brotli files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment