# Enable URL rewriting
RewriteEngine On

# Security headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options DENY
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Hide .htaccess file
<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>

# Hide config file
<Files config.php>
    Order allow,deny
    Deny from all
</Files>

# Prevent directory listing
Options -Indexes

# Set default character encoding
AddDefaultCharset UTF-8

# PHP settings
<IfModule mod_php7.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value error_log logs/error.log
    php_value max_execution_time 30
    php_value memory_limit 128M
    php_value upload_max_filesize 5M
    php_value post_max_size 6M
</IfModule>

<IfModule mod_php8.c>
    php_flag display_errors Off
    php_flag log_errors On
    php_value error_log logs/error.log
    php_value max_execution_time 30
    php_value memory_limit 128M
    php_value upload_max_filesize 5M
    php_value post_max_size 6M
</IfModule>

# Compress output
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

# Cache static files
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/icon "access plus 1 month"
    ExpiresByType text/html "access plus 1 hour"
</IfModule>

# Clean URLs (optional - uncomment if you want pretty URLs)
# RewriteRule ^article/([0-9]+)/?$ article.php?id=$1 [L,QSA]
# RewriteRule ^category/([0-9]+)/?$ index.php?category=$1 [L,QSA]
# RewriteRule ^search/([^/]+)/?$ index.php?search=$1 [L,QSA]
