# Indianapolis Hub - .htaccess Configuration

# Enable Rewrite Engine
RewriteEngine On

# Force HTTPS (uncomment when SSL is set up)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove www (or add www - choose one)
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Pretty URLs (optional)
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

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

# Browser Caching
<IfModule mod_expires.c>
    ExpiresActive On
    
    # Images
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    
    # CSS and JavaScript
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    
    # HTML and other text
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType application/json "access plus 0 seconds"
</IfModule>

# 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 type sniffing
    Header always set X-Content-Type-Options "nosniff"
    
    # Referrer Policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    
    # Remove server signature
    Header unset Server
    Header unset X-Powered-By
</IfModule>

# Protect sensitive files
<FilesMatch "^(config\.php|\.htaccess|\.htpasswd|composer\.json|composer\.lock|README\.md)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protect directories
Options -Indexes

# Protect cache directory (but allow reading by PHP)
<Directory "cache">
    Options -Indexes
    <FilesMatch "\.json$">
        Order allow,deny
        Deny from all
    </FilesMatch>
</Directory>

# Protect logs directory
<Directory "logs">
    Options -Indexes
    Order allow,deny
    Deny from all
</Directory>

# Prevent access to PHP files in cache and logs
<FilesMatch "^(cache|logs)/.*\.php$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Error Pages (create these if you want custom error pages)
# ErrorDocument 404 /404.php
# ErrorDocument 500 /500.php

# Disable directory browsing
Options -Indexes

# Follow symbolic links (if needed)
# Options +FollowSymLinks

# Charset
AddDefaultCharset UTF-8

# Performance: Remove ETags
Header unset ETag
FileETag None
