# ============================================================================
#  Fahad Zari — Apache / cPanel configuration
# ============================================================================

Options -Indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /fahdzari.com/

  # Force HTTPS (uncomment after installing an SSL certificate)
  # RewriteCond %{HTTPS} !=on
  # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # www redirect (uncomment if preferred)
  # RewriteCond %{HTTP_HOST} ^fahdzari\.com [NC]
  # RewriteRule ^ https://www.fahdzari.com%{REQUEST_URI} [L,R=301]

  # Block internal / development directories from direct web access
  RewriteRule ^(tools|includes|config)/ - [F,L]

  # Never rewrite real files or directories
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Pretty URLs
  RewriteRule ^sitemap\.xml$ sitemap.php [L]
  RewriteRule ^product/([a-z0-9-]+)/?$ product.php?slug=$1 [L,QSA]
  RewriteRule ^category/([a-z0-9-]+)/?$ category.php?slug=$1 [L,QSA]
  RewriteRule ^search/?$ search.php [L,QSA]
  RewriteRule ^about/?$ about.php [L,QSA]
  RewriteRule ^contact/?$ contact.php [L,QSA]
  RewriteRule ^privacy/?$ privacy.php [L,QSA]
  RewriteRule ^terms/?$ terms.php [L,QSA]
  RewriteRule ^shipping/?$ shipping.php [L,QSA]
  RewriteRule ^returns/?$ returns.php [L,QSA]
  RewriteRule ^credits/?$ credits.php [L,QSA]

  # Single-segment catch-all → category slug (bridal-dresses, mehndi, walima, party-suits …)
  RewriteRule ^([a-z0-9-]+)/?$ category.php?slug=$1 [L,QSA]
</IfModule>

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

# ----------------------------------------------------------------------------
# Browser caching
# ----------------------------------------------------------------------------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/svg+xml "access plus 1 year"
  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"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

# ----------------------------------------------------------------------------
# Security headers
# ----------------------------------------------------------------------------
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set Permissions-Policy "geolocation=(self), microphone=()"
</IfModule>

# Block access to sensitive files
<FilesMatch "^(config\.php|config\.local\.php|database\.sql|router\.php|\.env|.*\.md|.*\.json)$">
  Require all denied
</FilesMatch>