RewriteEngine On

# Enable browser caching for images
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 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/svg+xml "access plus 1 year"
</IfModule>

# Cache control headers
<IfModule mod_headers.c>
    <FilesMatch "\.(webp|jpg|jpeg|png|gif|svg)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

# Don't rewrite actual files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Admin directory - let it handle itself
RewriteRule ^admin/ - [L]

# Static pages
RewriteRule ^about/?$ about.php [L]
RewriteRule ^contact/?$ contact.php [L]
RewriteRule ^privacy/?$ privacy.php [L]
RewriteRule ^terms/?$ terms.php [L]
RewriteRule ^search/?$ search.php [L]

# Articles with date-based URLs: /2025/08/16/article-title
# Capture the full path and send as slug parameter
RewriteRule ^(\d{4}/\d{2}/\d{2}/.+)$ view-article.php?slug=$1 [L,QSA]

# Homepage
RewriteRule ^$ index.php [L]