# Secret Links - Apache Configuration

# Enable RewriteEngine
RewriteEngine On

# Security Headers
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "DENY"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "no-referrer"
Header set Content-Security-Policy "default-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com https://cdnjs.cloudflare.com; img-src 'self' data:; script-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com https://cdnjs.cloudflare.com;"
Header set Permissions-Policy "geolocation=(), microphone=(), camera=()"

# Redirect to HTTPS (uncomment if you have SSL)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Main rewrite rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

# Block access to sensitive files
<FilesMatch "\.(json|log|md|lock)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Block access to hidden files
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Block access to storage directory
<IfModule mod_rewrite.c>
    RewriteRule ^storage/ - [F,L]
</IfModule>

# Block access to src directory
<IfModule mod_rewrite.c>
    RewriteRule ^src/ - [F,L]
</IfModule>

# Block access to views directory
<IfModule mod_rewrite.c>
    RewriteRule ^views/ - [F,L]
</IfModule>

# Disable directory browsing
Options -Indexes

# PHP Settings (if allowed)
<IfModule mod_php.c>
    php_flag display_errors off
    php_flag log_errors on
    php_value max_execution_time 60
    php_value max_input_time 60
    php_value memory_limit 128M
    php_value post_max_size 10M
    php_value upload_max_filesize 10M
</IfModule>

# Cache Control for static files
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

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