Skip to content

Instantly share code, notes, and snippets.

@RaschidJFR
Forked from julianpoemp/.angular-htaccess.md
Last active November 7, 2021 19:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RaschidJFR/f6d21a03b0692f5c7a6a23954003f00b to your computer and use it in GitHub Desktop.
Save RaschidJFR/f6d21a03b0692f5c7a6a23954003f00b to your computer and use it in GitHub Desktop.
Optimal .htaccess configuration for Angular 8, Angular 7, Angular 6, Angular 5 (and older) app in production incl. fix for the angular browser caching issue.
# Taken from [Angular Deploymenr](https://angular.io/guide/deployment) Guide.
#
# INSTRUCTIONS:
# 1. Place this file next to the app's index.html.
# 2. Optional: If you serve your app from a subfolder in your domain,
#
# Gist forked from: [julianpoemp](https://gist.github.com/julianpoemp/bcf277cb56d2420cc53ec630a04a3566)
# Check for new versions of this gist: https://gist.github.com/RaschidJFR/f6d21a03b0692f5c7a6a23954003f00b
# v1.1.0
# use this if your app directly on the root of the domain,
# e.g. http://example_domain.com/index.html
<IfModule mod_rewrite.c>
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html...
RewriteRule ^ /index.html
#... Or use this instead if you server your app from a subfolder:
# RewriteRule ^ /path/or/subfolder/index.html
</IfModule>
# Disable caching so your user's always see your app's latest version.
<FilesMatch "\.(html|htm|js|json|css)$">
<IfModule mod_headers.c>
FileETag None
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Mon, 10 Apr 1972 00:00:00 GMT"
</IfModule>
</FilesMatch>
#
# It is recommended to add these tags to your index.html, too:
# <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
# <meta http-equiv="Pragma" content="no-cache">
# <meta http-equiv="Expires" content="0">
#------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment