Skip to content

Instantly share code, notes, and snippets.

@jdefez
Created November 10, 2019 15:28
Show Gist options
  • Select an option

  • Save jdefez/e2f0ff11ef8115f9e8143b78370ec5fb to your computer and use it in GitHub Desktop.

Select an option

Save jdefez/e2f0ff11ef8115f9e8143b78370ec5fb to your computer and use it in GitHub Desktop.
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Port} ^80$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Serve the file if it's actually a file on the server
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# If not rewrite the uri to serve index.html
RewriteRule ^(.*) /index.html
# if we're serving index.html, set CACHEBUSTER environement
SetEnvIf Request_URI "^/index.html$" CACHEBUSTER=true
# if we're hitting on the root too
SetEnvIf Request_URI "^/$" CACHEBUSTER=true
# And add cache busting headers if the environment is CACHEBUSTER
Header unset ETag env=CACHEBUSTER
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" env=CACHEBUSTER
Header set Pragma "no-cache" env=CACHEBUSTER
Header set Expires "Wed, 11 Jan 1986 05:00:00 GMT" env=CACHEBUSTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment