Skip to content

Instantly share code, notes, and snippets.

@MPrtenjak
Last active August 28, 2022 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MPrtenjak/7ce72b4ec03fb0191484a649f38d29c4 to your computer and use it in GitHub Desktop.
Save MPrtenjak/7ce72b4ec03fb0191484a649f38d29c4 to your computer and use it in GitHub Desktop.
Apache .htaccess file for running Blazor Web App
<IfModule mod_headers.c>
# Serve brotli compressed files if they exist and the client accepts brotli.
RewriteCond "%{HTTP:Accept-encoding}" "br"
RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
RewriteRule "^(.*)\.(js|json|css|dll|dat|blat|wasm)$" "$1\.$2\.br" [QSA]
# Serve gzip compressed files if they exist and the client accepts gzip.
RewriteCond "%{HTTP:Accept-encoding}" "gz"
RewriteCond "%{REQUEST_FILENAME}\.gz" "-s"
RewriteRule "^(.*)\.(js|json|css|dll|dat|blat|wasm)$" "$1\.$2\.gz" [QSA]
# Serve correct content types, and prevent double compression.
RewriteRule "\.css\.br$" "-" [T=text/css,E=no-brotli:1]
RewriteRule "\.js\.br$" "-" [T=text/javascript,E=no-brotli:1]
RewriteRule "\.json\.br$" "-" [T=application/json,E=no-brotli:1]
RewriteRule "\.dll\.br$" "-" [T=T=application/octet-stream,E=no-brotli:1]
RewriteRule "\.dat\.br$" "-" [T=application/octet-stream,E=no-brotli:1]
RewriteRule "\.blat\.br$" "-" [T=application/octet-stream,E=no-brotli:1]
RewriteRule "\.wasm\.br$" "-" [T=application/wasm,E=no-brotli:1]
# Serve correct content types, and prevent double compression.
RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1]
RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
RewriteRule "\.json\.gz$" "-" [T=application/json,E=no-gzip:1]
RewriteRule "\.dll\.gz$" "-" [T=T=application/octet-stream,E=no-gzip:1]
RewriteRule "\.dat\.gz$" "-" [T=application/octet-stream,E=no-gzip:1]
RewriteRule "\.blat\.gz$" "-" [T=application/octet-stream,E=no-gzip:1]
RewriteRule "\.wasm\.gz$" "-" [T=application/wasm,E=no-gzip:1]
<FilesMatch "(\.js\.br|\.css\.br|\.json\.br|\.dll\.br|\.dat\.br|\.blat\.br|\.wasm\.br)$">
# Serve correct encoding type.
Header set Content-Encoding br
# Force proxies to cache brotli & non-brotli
Header append Vary Accept-Encoding
</FilesMatch>
<FilesMatch "(\.js\.gz|\.css\.gz|\.json\.gz|\.dll\.gz|\.dat\.gz|\.blat\.gz|\.wasm\.gz)$">
# Serve correct encoding type.
Header set Content-Encoding gzip
# Force proxies to cache gzipped & non-gzipped
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-directory/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-directory/index.html [L]
</IfModule>
@MPrtenjak
Copy link
Author

Just update string 'sub-directory' (2x) with correct directory path of your app on Apache file system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment