Skip to content

Instantly share code, notes, and snippets.

@MetaiR
Forked from julianpoemp/.angular-htaccess.md
Created April 27, 2019 15:21
Show Gist options
  • Save MetaiR/341505b554d45433ca83d072535b5ae4 to your computer and use it in GitHub Desktop.
Save MetaiR/341505b554d45433ca83d072535b5ae4 to your computer and use it in GitHub Desktop.
Optimal .htaccess configuration for Angular 7, Angular 6, Angular 5 (and older) app in production incl. fix for the angular browser caching issue.
# INSTRUCTION:
# Place this file next to the app's index.html.
# There are two options for the redirection:
# Option 1) (default): Your app is directly on the root of the domain.
# Option 2): Your app is placed in a subfolder from the root of the domain.
#
# If you have issues with browser caching you can uncomment the BROWSER CACHING part
# For new versions of this Gist go to:
# https://gist.github.com/julianpoemp/bcf277cb56d2420cc53ec630a04a3566
# Version 1.0.0
#------------ REDIRECTION option 1)
# 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
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
#------------
#------------ REDIRECTION option 2)
# Use this if your app is not directly on the root of the domain,
# e.g. http://example_domain.com/directory_path/index.html
# Important: replace directory_path with the relative path from
# the domain to the index.html. Keep the first "/". Don't forget to comment option 1).
#<IfModule mod_rewrite.c>
# RewriteEngine on
# RewriteCond %{REQUEST_FILENAME} -s [OR]
# RewriteCond %{REQUEST_FILENAME} -l [OR]
# RewriteCond %{REQUEST_FILENAME} -d
# RewriteRule ^.*$ - [NC,L]
# RewriteRule ^(.*) /directory_path/index.html [NC,L]
#</IfModule>
#------------
# #------------ BROWSER CACHING
# disable browser caching in production.
#<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