# AI Visibility Tracker - Apache Configuration

# Enable rewrite engine
RewriteEngine On

# Set base directory
RewriteBase /

# Redirect to HTTPS (optional - uncomment if using HTTPS)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Security headers
<IfModule mod_headers.c>
    Header set X-Frame-Options "DENY"
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Enable HSTS if using HTTPS
    # Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>

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

# Cache static files
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/json "access plus 1 hour"
</IfModule>

# Deny access to sensitive files
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

<Files "config.php">
    Require all denied
</Files>

<Files "worker.php">
    Require all denied
</Files>

<Files "cron.php">
    Require all denied
</Files>

# Block access to log files
<FilesMatch "\.log$">
    Require all denied
</FilesMatch>

# Block access to SQL files
<FilesMatch "\.sql$">
    Require all denied
</FilesMatch>

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

# Handle installer (if it exists)
RewriteCond %{REQUEST_URI} ^/install/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /install/index.php [QSA,L]

# Prevent directory listing
Options -Indexes

# Set upload limits
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_execution_time 300
php_value max_input_time 300
php_value memory_limit 256M