Last active
March 24, 2025 22:33
-
-
Save 3m1n3nc3/9177774c8dbc1d7f26d5c1f6e47ad602 to your computer and use it in GitHub Desktop.
Perfect .htaccess file for SPA hosting on Apache servers
This file contains hidden or 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
<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> |
Author
3m1n3nc3
commented
Jul 24, 2022
•
- Create a new .htaccess file at the root directory where your index.html file exist
- 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