Options -Indexes
RewriteEngine On

# Force HTTPS (uncomment after SSL is active)
# RewriteCond %{HTTPS} off
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Block direct access to sensitive files
RewriteRule ^(config\.php|data/.*|includes/.*)$ - [F,L]

RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^robots\.txt$ robots.php [L]
RewriteRule ^ads\.txt$ ads-txt.php [L]
RewriteRule ^indexnow-key\.txt$ indexnow.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([A-Za-z0-9\-]+)/?$ post.php?slug=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tag/([A-Za-z0-9\-]+)/?$ tag.php?slug=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([A-Za-z0-9\-]+)/?$ category.php?slug=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^join/([0-9]+)/?$ go.php?id=$1 [L,QSA]

# Pages: /about-us, /privacy-policy …
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9\-]+)/?$ page.php?slug=$1 [L,QSA]

# Everything else that does not exist → 404 page (also handles 301 redirects)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ page.php?slug=__404 [L,QSA]

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json application/xml text/plain
</IfModule>
