Skip to content

Instantly share code, notes, and snippets.

@3m1n3nc3
Last active March 24, 2025 22:33
Show Gist options
  • Save 3m1n3nc3/9177774c8dbc1d7f26d5c1f6e47ad602 to your computer and use it in GitHub Desktop.
Save 3m1n3nc3/9177774c8dbc1d7f26d5c1f6e47ad602 to your computer and use it in GitHub Desktop.
Perfect .htaccess file for SPA hosting on Apache servers
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# No caching for all files
<FilesMatch ".*">
Header set Cache-Control "no-cache, no-store, must-revalidate"
</FilesMatch>
# Caching for static assets
<FilesMatch "\.(jpg|jpeg|gif|png|svg|webp|js|css|eot|otf|ttf|ttc|woff|woff2|font\.css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
@3m1n3nc3
Copy link
Author

3m1n3nc3 commented Jul 24, 2022

  1. Create a new .htaccess file at the root directory where your index.html file exist
  2. Copy the above code and paste in the file you just created, save and voila.

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