# AI Image Manager - Apache Configuration

# Enable rewriting
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Prevent access to data directory
    RewriteRule ^data/ - [F,L]
    
    # Prevent access to config file directly
    RewriteRule ^config\.php$ - [F,L]
    RewriteRule ^functions\.php$ - [F,L]
</IfModule>

# Protect data directory
<FilesMatch "\.sqlite$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Protect PHP files from direct access
<FilesMatch "^(config|functions)\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Allow access to uploads
<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^uploads/.*\.(jpg|jpeg|png|gif|webp)$ - [L]
</IfModule>

# Set upload limits (if allowed by host)
<IfModule mod_php7.c>
    php_value upload_max_filesize 20M
    php_value post_max_size 25M
    php_value max_execution_time 300
    php_value max_input_time 300
    php_value memory_limit 256M
</IfModule>

# Disable directory browsing
Options -Indexes

# Set default character set
AddDefaultCharset UTF-8

# Cache images
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
</IfModule>

# Compress text files
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json
</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>
