1- <IfModule mod_rewrite.c>
2- # Start Engine
3- RewriteEngine On
4-
5- # Define additional rules below
6- #
7-
8- # Cache control headers
9- <IfModule mod_headers.c>
10- <filesMatch ".(js|css|xml|gz|html|php)$">
11- Header append Vary: Accept-Encoding
12- </filesMatch>
13- <filesMatch "\.(ico|flv|gif|swf|eot|woff|otf|ttf|svg)$">
14- Header set Cache-Control "max-age=31536000, public"
15- </filesMatch>
16- <filesMatch "\.(jpg|jpeg|png)$">
17- Header set Cache-Control "max-age=31536000, public"
18- </filesMatch>
19- <filesMatch "\.(css)$">
20- Header set Cache-Control "max-age=2592000, public"
21- </filesMatch>
22- <filesMatch "\.(js)$">
23- Header set Cache-Control "max-age=2592000, public"
24- </filesMatch>
25- <filesMatch "\.(x?html?)$">
26- Header set Cache-Control "public, must-revalidate"
27- </filesMatch>
28- <filesMatch "\.(x?php)$">
29- Header set Cache-Control "private, must-revalidate"
30- </filesMatch>
31- </IfModule>
32-
33- # Mod security
34- <IfModule mod_security.c>
35- SecFilterScanPOST Off
36- </IfModule>
37-
38- # Mod Speling
39- <IfModule mod_speling.c>
40- CheckCaseOnly On
41- CheckSpelling On
42- </IfModule>
1+ # Performance-optimized minimal .htaccess
2+
3+ # Compression: prefer Brotli, fallback to Gzip/Deflate
4+ <IfModule mod_brotli.c>
5+ AddOutputFilterByType BROTLI_COMPRESS \
6+ text/html text/plain text/css text/xml \
7+ application/javascript application/json application/xml application/xhtml+xml \
8+ image/svg+xml
9+ </IfModule>
10+
11+ <IfModule mod_deflate.c>
12+ AddOutputFilterByType DEFLATE \
13+ text/html text/plain text/css text/xml \
14+ application/javascript application/json application/xml application/xhtml+xml \
15+ image/svg+xml
16+ # Skip already-compressed binary formats
17+ SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|webp|avif|ico)$" no-gzip dont-vary
4318</IfModule>
4419
20+ # Caching: long-lived for static assets, revalidate dynamic pages
21+ <IfModule mod_headers.c>
22+ # Ensure caches differentiate compressed/uncompressed
23+ <FilesMatch "\.(?:css|js|mjs|xml|json|html|svg)$">
24+ Header merge Vary "Accept-Encoding"
25+ </FilesMatch>
26+
27+ # Immutable for hashed assets (e.g., app-abcdef12.js or app.abcdef12.css)
28+ <FilesMatch "(?:-[0-9a-f]{8,}|\.[0-9a-f]{8,})\.(?:css|js|mjs)$">
29+ Header set Cache-Control "public, max-age=31536000, immutable"
30+ </FilesMatch>
31+
32+ # Images and fonts: cache for 1 year (safe to mark immutable)
33+ <FilesMatch "\.(?:ico|gif|png|jpe?g|svg|webp|avif|eot|ttf|otf|woff2?)$">
34+ Header set Cache-Control "public, max-age=31536000, immutable"
35+ </FilesMatch>
36+
37+ # Non-hashed CSS/JS: cache for 30 days
38+ <FilesMatch "\.(?:css|js|mjs)$">
39+ Header set Cache-Control "public, max-age=2592000"
40+ </FilesMatch>
41+
42+ # HTML: always revalidate
43+ <FilesMatch "\.(?:x?html?)$">
44+ Header set Cache-Control "no-cache, must-revalidate"
45+ </FilesMatch>
46+
47+ # Prefer Cache-Control/Last-Modified over ETag
48+ Header unset ETag
49+ </IfModule>
50+
51+ # Disable ETags at the source
52+ FileETag None
53+
54+ # Optional: allow cross-origin font loads (prevents 403/blocked fonts)
55+ <IfModule mod_headers.c>
56+ <FilesMatch "\.(?:eot|ttf|otf|woff2?)$">
57+ Header set Access-Control-Allow-Origin "*"
58+ </FilesMatch>
59+ </IfModule>
60+
61+ <Files "service-worker.js">
62+ Header set Cache-Control "no-cache, must-revalidate"
63+ </Files>
64+
65+ # Fallback Expires headers (extra cache control for older proxies/CDNs)
4566<IfModule mod_expires.c>
46- # Set expiration for different file types
4767 ExpiresActive On
68+
69+ # Default: 30 days
70+ ExpiresDefault "access plus 30 days"
71+
72+ # HTML always revalidate
4873 ExpiresByType text/html "access plus 600 seconds"
4974 ExpiresByType application/xhtml+xml "access plus 600 seconds"
50- ExpiresByType image/gif "access plus 1 year"
51- ExpiresByType image/png "access plus 1 year"
52- ExpiresByType image/jpg "access plus 1 year"
53- ExpiresByType image/jpeg "access plus 1 year"
54- ExpiresByType image/x-icon "access plus 1 year"
55- ExpiresByType image/svg+xml "access plus 1 year"
56- ExpiresByType audio/ogg "access plus 1 year"
57- ExpiresByType video/mp4 "access plus 1 year"
58- ExpiresByType video/ogg "access plus 1 year"
59- ExpiresByType video/webm "access plus 1 year"
60- ExpiresByType application/atom+xml "access plus 1 hour"
61- ExpiresByType application/rss+xml "access plus 1 hour"
62- ExpiresByType application/pdf "access plus 1 month"
63- ExpiresByType text/css "access 1 month"
64- ExpiresByType application/javascript "access 1 month"
65- ExpiresByType text/x-javascript "access 1 month"
66- ExpiresByType text/x-component "access plus 1 month"
67- ExpiresByType application/x-shockwave-flash "access 1 month"
68- ExpiresByType font/opentype "access plus 1 month"
69- ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
70- ExpiresByType application/x-font-ttf "access plus 1 month"
71- ExpiresByType application/font-woff "access plus 1 month"
72- ExpiresByType application/font-woff2 "access plus 1 month"
73- ExpiresDefault "access plus 30 days"
74- </IfModule>
7575
76- <IfModule mod_gzip.c>
77- # Enable gzip compression for resources
78- mod_gzip_on Yes
79- mod_gzip_dechunk Yes
80- mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
81- mod_gzip_item_include handler ^application/x-httpd-php
82- mod_gzip_item_include mime ^application/javascript$
83- mod_gzip_item_include mime ^application/x-javascript$
84- mod_gzip_item_include mime ^text/.*
85- mod_gzip_item_exclude mime ^image/.*
86- mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
76+ # Images, video and fonts: 1 year
77+ ExpiresByType image/* "access plus 1 year"
78+ ExpiresByType font/* "access plus 1 year"
79+ ExpiresByType video/* "access plus 1 year"
80+
81+ # CSS & JS: 1 month
82+ ExpiresByType text/css "access plus 1 month"
83+ ExpiresByType application/javascript "access plus 1 month"
8784</IfModule>
8885
89- <IfModule pagespeed_module>
90- # Page Speed
91- ModPagespeed on
92- ModPagespeedEnableFilters rewrite_css,combine_css
93- ModPagespeedEnableFilters recompress_images
94- ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
95- ModPagespeedEnableFilters collapse_whitespace,remove_comments
96- </IfModule>
86+ # Lightweight security headers
87+ <IfModule mod_headers.c>
88+ Header set X-Content-Type-Options "nosniff"
89+ Header set X-Frame-Options "SAMEORIGIN"
90+ Header set Referrer-Policy "strict-origin-when-cross-origin"
91+ Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"
92+ </IfModule>
0 commit comments