# Golden Elegance — Apache settings (most Iranian shared hosts run Apache/LiteSpeed)

Options -Indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
  RewriteEngine On

  # One address for search engines and visitors: https://golden-elegance-jewelry.ir
  # http:// and www. forms move there permanently (301), so Google sees one site, not four.
  # Only on the real domain: a local preview or a temporary host name is never redirected.
  # /.well-known/ stays on plain http: AutoSSL renews the certificate through it, and a redirect there
  # can make the renewal fail (then the certificate expires and HSTS locks visitors out).
  RewriteCond %{HTTP_HOST} ^(www\.)?golden-elegance-jewelry\.ir$ [NC]
  RewriteCond %{REQUEST_URI} !^/\.well-known/
  RewriteCond %{HTTPS} !=on [OR]
  RewriteCond %{HTTP_HOST} ^www\. [NC]
  RewriteRule ^ https://golden-elegance-jewelry.ir%{REQUEST_URI} [R=301,L,NE]
  # /index.php is the home page: one URL for it, «/»
  RewriteCond %{HTTP_HOST} ^golden-elegance-jewelry\.ir$ [NC]
  RewriteCond %{THE_REQUEST} \s/index\.php[\s?] [NC]
  RewriteRule ^index\.php$ https://golden-elegance-jewelry.ir/ [R=301,L]

  RewriteRule ^sitemap\.xml$ sitemap.php [L]
  # Never serve the private folder (even if left inside the web root), local tooling,
  # or img/ and img-name/ — the jeweler's original uploads (photos can carry GPS location)
  RewriteRule ^(private|tools|docs|img|img-name|devtools)(/|$) - [F,L]
</IfModule>

AddType font/woff2 .woff2
AddType image/avif .avif
AddType image/webp .webp
AddType video/mp4 .mp4
AddType audio/mpeg .mp3

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()"
  Header always set Cross-Origin-Opener-Policy "same-origin"
  # once the site is on HTTPS (cPanel → SSL/TLS), browsers will only ever use HTTPS for it
  Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
  Header always unset X-Powered-By
</IfModule>

# Only the pages and APIs run PHP; any other .php file anywhere is refused
<IfModule mod_rewrite.c>
  RewriteCond %{REQUEST_URI} \.(php[0-9]?|phtml|phar)$ [NC]
  RewriteCond %{REQUEST_URI} !^/(index|gold-price|collections|collection|piece|sitemap|install)\.php$ [NC]
  RewriteCond %{REQUEST_URI} !^/(api/(prices|shop|chat-log)|admin/index)\.php$ [NC]
  RewriteRule ^ - [F,L]
</IfModule>

# Fonts, vendor scripts and images change rarely: cache them for a long time.
# Site CSS/JS are cached for a day, so an update reaches visitors quickly.
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType image/avif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType audio/mpeg "access plus 1 month"
  ExpiresByType text/css "access plus 1 day"
  ExpiresByType application/javascript "access plus 1 day"
  ExpiresByType text/javascript "access plus 1 day"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json application/xml image/svg+xml
</IfModule>

# Local tooling and notes that sit in the project folder: never served
<FilesMatch "\.(bat|cmd|md)$">
  Require all denied
</FilesMatch>
