# =====================================================================
# .htaccess — Petcu Partners
# Rewrites + cache headers + securitate de bază pentru LiteSpeed/Apache
# =====================================================================

# UTF-8 ca default pentru toate paginile servite
AddDefaultCharset UTF-8

# ---------------------------------------------------------------------
# Rewrite engine
# ---------------------------------------------------------------------
RewriteEngine On

# Sitemap-ul "standard" /sitemap.xml → script-ul nostru dinamic
RewriteRule ^sitemap\.xml$ /sitemap.php [L]

# Forțăm HTTPS (Google indexează doar versiunea HTTPS dacă există)
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=localhost
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Forțăm versiunea fără "www" (canonical host = petcupartners.ro, NU www.petcupartners.ro)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Blochează accesul direct la fișierele de date (limbi, servicii)
RewriteRule ^(lang|pagini)/ - [F,L]

# ---------------------------------------------------------------------
# Cache headers — pagini cu content static lung (CSS, JS, imagini, fonturi)
# ---------------------------------------------------------------------
<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 6 months"
    ExpiresByType image/jpeg               "access plus 6 months"
    ExpiresByType image/svg+xml            "access plus 6 months"
    ExpiresByType image/webp               "access plus 6 months"
    ExpiresByType image/x-icon             "access plus 1 year"
    ExpiresByType font/woff                "access plus 1 year"
    ExpiresByType font/woff2               "access plus 1 year"
    ExpiresByType text/html                "access plus 0 seconds"
    ExpiresByType application/xml          "access plus 1 hour"
</IfModule>

# ---------------------------------------------------------------------
# Compresie GZIP (PageSpeed boost — Google ține cont de viteză la ranking)
# ---------------------------------------------------------------------
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE application/javascript application/json application/xml
    AddOutputFilterByType DEFLATE image/svg+xml font/woff font/woff2
</IfModule>

# ---------------------------------------------------------------------
# Headere de securitate (mici, dar Google le ia în calcul ca semnale de calitate)
# ---------------------------------------------------------------------
<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=(), microphone=(), camera=()"
</IfModule>

# ---------------------------------------------------------------------
# Pagini de eroare custom (opțional — poți crea 404.php / 500.php)
# ---------------------------------------------------------------------
# ErrorDocument 404 /404.php
