# LinkBoostify - Performance Optimization
# Zero Visual Changes - Backend Speed Improvements Only

# ====================================
# GZIP Compression (70% Size Reduction)
# ====================================
<IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE image/svg+xml
    
    # Compress fonts
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/woff
    AddOutputFilterByType DEFLATE font/woff2
    AddOutputFilterByType DEFLATE application/font-woff
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
</IfModule>

# ====================================
# Browser Caching (Faster Repeat Visits)
# ====================================
<IfModule mod_expires.c>
    ExpiresActive On
    
    # Images - 1 year
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/jpg "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"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    
    # CSS & JavaScript - 1 month
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    
    # Fonts - 1 year
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    
    # HTML - 1 hour
    ExpiresByType text/html "access plus 1 hour"
    
    # Default - 1 week
    ExpiresDefault "access plus 1 week"
</IfModule>

# ====================================
# Cache-Control Headers
# ====================================
<IfModule mod_headers.c>
    # Cache static assets
    <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|css|js|woff|woff2|ttf|otf)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
    
    # Don't cache PHP/HTML
    <FilesMatch "\.(php|html)$">
        Header set Cache-Control "no-cache, must-revalidate"
    </FilesMatch>
</IfModule>

# ====================================
# Clean URLs (Already Working)
# ====================================
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Redirect www to non-www (Optional - for consistency)
    # RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    # RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    # Blog clean URLs
    RewriteRule ^blog/([a-zA-Z0-9-]+)$ blog-detail.php?slug=$1 [L,QSA]
</IfModule>

# ====================================
# Security Headers (Bonus)
# ====================================
<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 sniffing
    Header always set X-Content-Type-Options "nosniff"
    
    # Referrer Policy
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ====================================
# File Upload Security
# ====================================
<FilesMatch "\.(php|phtml|php3|php4|php5|php7|phps)$">
    <IfModule mod_authz_core.c>
        # Deny access to PHP files in uploads
        <If "%{REQUEST_URI} =~ m#/uploads/#">
            Require all denied
        </If>
    </IfModule>
</FilesMatch>
