# Enable rewrite engine RewriteEngine On # Force HTTPS (handled by Pangolin/Cloudflare, but just in case) # RewriteCond %{HTTPS} off # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Remove trailing slashes (except for directories) RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Security headers Header set X-Content-Type-Options "nosniff" Header set X-Frame-Options "SAMEORIGIN" Header set X-XSS-Protection "1; mode=block" Header set Referrer-Policy "strict-origin-when-cross-origin" # Prevent directory listing Options -Indexes # Block access to hidden files Require all denied # Cache static assets ExpiresActive On ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType image/webp "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year" # Gzip compression AddOutputFilterByType DEFLATE text/html text/css application/javascript text/plain application/json image/svg+xml # Custom error pages ErrorDocument 404 /404.php