|
| 1 | +# ------------------------------------------ |
| 2 | +# 🔒 Disable PHP execution for security |
| 3 | +# ------------------------------------------ |
| 4 | +<FilesMatch "\.(php|php[0-9]*)$"> |
| 5 | + Order allow,deny |
| 6 | + Deny from all |
| 7 | +</FilesMatch> |
| 8 | + |
| 9 | +# Alternative: Serve PHP files as plain text (uncomment if preferred) |
| 10 | +# <FilesMatch "\.(php|php[0-9]*)$"> |
| 11 | +# SetHandler none |
| 12 | +# ForceType text/plain |
| 13 | +# </FilesMatch> |
| 14 | + |
| 15 | +# ------------------------------------------ |
| 16 | +# 🚀 Enable browser caching for static files |
| 17 | +# ------------------------------------------ |
| 18 | +<IfModule mod_expires.c> |
| 19 | + ExpiresActive On |
| 20 | + |
| 21 | + # Set long expiration for common static file types |
| 22 | + ExpiresByType image/jpg "access plus 1 year" |
| 23 | + ExpiresByType image/jpeg "access plus 1 year" |
| 24 | + ExpiresByType image/gif "access plus 1 year" |
| 25 | + ExpiresByType image/png "access plus 1 year" |
| 26 | + ExpiresByType image/svg+xml "access plus 1 year" |
| 27 | + ExpiresByType text/css "access plus 1 month" |
| 28 | + ExpiresByType text/javascript "access plus 1 month" |
| 29 | + ExpiresByType application/javascript "access plus 1 month" |
| 30 | + ExpiresByType application/x-javascript "access plus 1 month" |
| 31 | + ExpiresByType application/font-woff2 "access plus 1 year" |
| 32 | + ExpiresByType application/font-woff "access plus 1 year" |
| 33 | + ExpiresByType application/vnd.ms-fontobject "access plus 1 year" |
| 34 | + ExpiresByType font/ttf "access plus 1 year" |
| 35 | + ExpiresByType font/otf "access plus 1 year" |
| 36 | +</IfModule> |
| 37 | + |
| 38 | +# ------------------------------------------ |
| 39 | +# 💨 Enable GZIP compression |
| 40 | +# ------------------------------------------ |
| 41 | +<IfModule mod_deflate.c> |
| 42 | + AddOutputFilterByType DEFLATE text/plain |
| 43 | + AddOutputFilterByType DEFLATE text/html |
| 44 | + AddOutputFilterByType DEFLATE text/xml |
| 45 | + AddOutputFilterByType DEFLATE text/css |
| 46 | + AddOutputFilterByType DEFLATE application/javascript |
| 47 | + AddOutputFilterByType DEFLATE application/x-javascript |
| 48 | + AddOutputFilterByType DEFLATE application/json |
| 49 | + AddOutputFilterByType DEFLATE application/xml |
| 50 | + AddOutputFilterByType DEFLATE application/font-woff2 |
| 51 | + AddOutputFilterByType DEFLATE application/font-woff |
| 52 | + AddOutputFilterByType DEFLATE font/ttf |
| 53 | + AddOutputFilterByType DEFLATE font/otf |
| 54 | + |
| 55 | + # Optional: compress everything except images |
| 56 | + SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary |
| 57 | +</IfModule> |
| 58 | + |
| 59 | +# ------------------------------------------ |
| 60 | +# 🎯 Leverage cache-control headers |
| 61 | +# ------------------------------------------ |
| 62 | +<IfModule mod_headers.c> |
| 63 | + <FilesMatch "\.(ico|jpg|jpeg|png|gif|svg|css|js|woff|woff2|ttf|otf|eot)$"> |
| 64 | + Header set Cache-Control "public, max-age=31536000, immutable" |
| 65 | + </FilesMatch> |
| 66 | +</IfModule> |
| 67 | + |
| 68 | +# ------------------------------------------ |
| 69 | +# 🛡️ Basic security headers |
| 70 | +# ------------------------------------------ |
| 71 | +<IfModule mod_headers.c> |
| 72 | + Header set X-Content-Type-Options "nosniff" |
| 73 | + Header set X-Frame-Options "SAMEORIGIN" |
| 74 | + Header set X-XSS-Protection "1; mode=block" |
| 75 | + Header always set Referrer-Policy "strict-origin-when-cross-origin" |
| 76 | +</IfModule> |
| 77 | + |
| 78 | +# ------------------------------------------ |
| 79 | +# 🔍 Optional: Redirect to HTTPS if not already handled globally |
| 80 | +# ------------------------------------------ |
| 81 | +# RewriteEngine On |
| 82 | +# RewriteCond %{HTTPS} off |
| 83 | +# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
| 84 | + |
| 85 | +# ------------------------------------------ |
| 86 | +# 🧼 Optional: Remove trailing slashes |
| 87 | +# ------------------------------------------ |
| 88 | +# RewriteCond %{REQUEST_FILENAME} !-d |
| 89 | +# RewriteRule ^(.+)/$ /$1 [R=301,L] |
0 commit comments