Created
November 28, 2017 07:26
-
-
Save up209d/c164d620f475f9ad616f03a0bdee5caa to your computer and use it in GitHub Desktop.
Single Page Application .htaccess (gzip and fallback)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AddEncoding gzip .gz | |
RewriteEngine on | |
#For all request has header contents Accept-encoding: gzip | |
RewriteCond %{HTTP:Accept-encoding} gzip | |
#For all browser except Konqueror | |
RewriteCond %{HTTP_USER_AGENT} !Konqueror | |
#For all filename case, if the name.ext.gz file exits so we do rewrite | |
#We can use flag like [OR] [AND] for condition | |
RewriteCond %{REQUEST_FILENAME}.gz -f | |
RewriteRule ^(.*\.(css|js|html|json|svg))$ $1.gz [QSA,L] | |
<Files *.css.gz> | |
ForceType text/css | |
</Files> | |
<Files *.js.gz> | |
ForceType application/javascript | |
</Files> | |
<Files *.html.gz> | |
ForceType text/html | |
</Files> | |
<Files *.json.gz> | |
ForceType application/json | |
</Files> | |
<Files *.svg.gz> | |
ForceType image/svg+xml | |
</Files> | |
#For Fallback API: | |
#Point to index.html and if index.html.gz is not found | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ index.html [QSA,L] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment