# PactForge — Apache rules
DirectoryIndex index.php

# Block direct access to internals
RedirectMatch 404 ^/(includes|database|lang)/
<FilesMatch "^(config\.php|config\.sample\.php|README\.md|dev-router\.php|\.env|errors\.log)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
    </IfModule>
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

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

    # Clean addresses, one per language: /pricing, /es/pricing, /templates/nda, /fr/templates/nda
    # (PHP sees PF_REWRITE and builds links this way; without these rules the site falls back to pricing.php?hl=es)
    RewriteRule ^ - [E=PF_REWRITE:1]
    RewriteRule ^sitemap\.xml$ sitemap.php [L,QSA]
    RewriteRule ^robots\.txt$ robots.php [L,QSA]
    RewriteRule ^llms\.txt$ llms.php [L,QSA]
    RewriteRule ^llms-full\.txt$ llms.php?full=1 [L,QSA]
    RewriteRule ^(es|fr|de|ar|it|pt|cs|ja)/?$ index.php?hl=$1 [L,QSA]
    RewriteRule ^(es|fr|de|ar|it|pt|cs|ja)/templates/([a-z0-9-]+)/?$ template.php?slug=$2&hl=$1 [L,QSA]
    RewriteRule ^templates/([a-z0-9-]+)/?$ template.php?slug=$1 [L,QSA]
    RewriteRule ^(es|fr|de|ar|it|pt|cs|ja)/([a-z_]+)/?$ $2.php?hl=$1 [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z_]+)/?$ $1.php [L,QSA]
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml text/css application/javascript application/json image/svg+xml
</IfModule>
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"
    ExpiresByType image/svg+xml "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
</IfModule>
AddType font/woff .woff
