# School Website - Security Configuration

# Enable RewriteEngine
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Redirect to public/ if accessing root
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ public/ [L]
</IfModule>

# Protect SQLite database files
<FilesMatch "\.(db|sqlite|sqlite3)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Protect backup files (but allow download from backups folder)
<FilesMatch "\.(sql|bak)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Prevent directory listing
Options -Indexes

# Allow access to PHP files
<FilesMatch "\.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# Set default charset
AddDefaultCharset UTF-8

# Enable GZIP 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"
</IfModule>

# Security headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# PHP settings (if allowed by hosting)
<IfModule mod_php.c>
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
    php_value max_execution_time 300
    php_value max_input_time 300
</IfModule>
