# PayTrack .htaccess Configuration

# Enable RewriteEngine
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /PayTrack/
    
    # Redirect to HTTPS (uncomment in production)
    # RewriteCond %{HTTPS} off
    # RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Prevent directory listing
Options -Indexes

# Protect configuration files
<FilesMatch "^(config\.php|database\.php)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protect SQL files
<FilesMatch "\.(sql)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Security Headers
<IfModule mod_headers.c>
    # Prevent clickjacking
    Header always set X-Frame-Options "SAMEORIGIN"
    
    # XSS Protection
    Header always set X-XSS-Protection "1; mode=block"
    
    # Prevent MIME sniffing
    Header always set X-Content-Type-Options "nosniff"
    
    # Referrer Policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Remove Server Info
    Header unset Server
    Header unset X-Powered-By
</IfModule>

# PHP Security Settings
<IfModule mod_php.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value error_log logs/php_errors.log
    php_flag expose_php Off
</IfModule>

# Set default character set
AddDefaultCharset UTF-8

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

# Browser Caching
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
</IfModule>

# Custom Error Pages (create these files if needed)
# ErrorDocument 404 /PayTrack/404.php
# ErrorDocument 403 /PayTrack/403.php
# ErrorDocument 500 /PayTrack/500.php

# Limit file uploads to specific directories
<FilesMatch "\.(php|php3|php4|php5|phtml)$">
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/PayTrack/assets/uploads/
        RewriteRule .* - [F,L]
    </IfModule>
</FilesMatch>
