# ============================================
# .htaccess - Security & Performance Configuration
# Bank Soal TKA
# ============================================
#
# SETUP INSTRUCTION:
# Rename this file to .htaccess and put di root folder project
#
# ============================================
# 1. SECURITY HEADERS
# ============================================
# Prevent directory listing
Options -Indexes
# Prevent access to sensitive files
Order allow,deny
Deny from all
# Deny access to config files
Deny from all
# ============================================
# 2. PREVENT FILE INCLUSION ATTACKS
# ============================================
# Disable script execution di uploads folder
php_flag engine off
AddType text/plain .php .phtml .php3 .php4 .php5 .php6 .php7 .phps .pht .phar .shtml .jsp .asp .aspx .cgi .pl .py .sh .bat
# ============================================
# 3. SECURITY HEADERS
# ============================================
# Prevent MIME sniffing
Header always set X-Content-Type-Options "nosniff"
# Clickjacking protection
Header always set X-Frame-Options "SAMEORIGIN"
# XSS Protection
Header always set X-XSS-Protection "1; mode=block"
# Referrer Policy
Header always set Referrer-Policy "no-referrer-when-downgrade"
# Remove server signature
Header always unset X-Powered-By
Header always unset X-AspNet-Version
Header always unset X-AspNetMvc-Version
# ============================================
# 4. PERFORMANCE - GZIP COMPRESSION
# ============================================
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json
# ============================================
# 5. CACHE CONTROL
# ============================================
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
# CSS & JS
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
# HTML (short cache)
ExpiresByType text/html "access plus 1 day"
# JSON (no cache)
ExpiresByType application/json "access plus 0 seconds"
# ============================================
# 6. PREVENT SQL INJECTION & XSS
# ============================================
# Block SQL injection attempts
RewriteEngine On
# Block common SQL injection patterns
RewriteCond %{QUERY_STRING} (\"|\'|exec|insert|select|union|drop|delete|create|update) [NC]
RewriteRule .* - [F]
# Block executable file uploads
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(exe|sh|bat|cmd|com|pif|scr)$ [NC]
RewriteRule .* - [F]
# Redirect to index.php (jika perlu routing)
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^api/(.*)$ api.php?route=$1 [QSA,L]
# ============================================
# 7. SSL/HTTPS REDIRECT (UNCOMMENT JIKA HTTPS)
# ============================================
#
# RewriteEngine On
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# ============================================
# 8. DISABLE DANGEROUS METHODS
# ============================================
Deny from all
# ============================================
# 9. CUSTOM ERROR PAGES (OPTIONAL)
# ============================================
# ErrorDocument 400 /error/400.php
# ErrorDocument 403 /error/403.php
# ErrorDocument 404 /error/404.php
# ErrorDocument 500 /error/500.php