# ============================================================
#  gen-codes.site — routing rules
#  - /admin  and /uploads are served directly (PHP panel + files)
#  - real files & folders are served as-is
#  - everything else falls back to the SPA (index.html) so the
#    React tool routes like /age-calculator.html keep working
# ============================================================

# Let /admin/ open its index.php, not the SPA's index.html
DirectoryIndex index.php index.html

# Avoid Apache content-negotiation surprises
Options -MultiViews

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # 0) Permanent redirects for retired duplicate blog posts
  Redirect 301 /blog/age-calculator.html /blog/how-the-age-calculator-works.html
  Redirect 301 /blog/base64-encoder.html /blog/base64-encode-decode-guide.html
  Redirect 301 /blog/password-generator.html /blog/how-to-use-password-generator.html
  Redirect 301 /blog/word-counter.html /blog/word-counter-guide.html

  # 1) NEVER hand these to the SPA — Apache serves them normally.
  RewriteRule ^admin(/|$)   - [L]
  RewriteRule ^uploads(/|$) - [L]

  # 2) If the request is a real file or a real directory, serve it as-is
  #    (this covers /assets/*, /blog/*.html, sitemap.xml, robots.txt, etc.)
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # 3) SPA fallback: send everything else to index.html
  RewriteRule ^ index.html [L]
</IfModule>

# ---- Small performance touch-ups (safe defaults) ----
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>
