# Friendly URLs
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /prompt/
    
    # Do not rewrite existing files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    # Unified Rule: /lang/slug_or_page
    # Example: /ar/image -> page=image
    # Example: /ar/my-post -> page=my-post (PHP will detect it's an article)
    RewriteRule ^(ar|en)/([^/]+)/?$ index.php?lang=$1&page=$2 [QSA,L]
    
    # Language Home: /ar -> index.php?lang=ar
    RewriteRule ^(ar|en)/?$ index.php?lang=$1&page=home [QSA,L]
    
    # Root Home
    RewriteRule ^/?$ index.php?page=home [QSA,L]

    # Sitemap
    RewriteRule ^sitemap\.xml$ sitemap-xml.php [L]
</IfModule>

# Caching
<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 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>

# Security Headers
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# Block access to hidden files
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Block access to JSON data files
<FilesMatch "\.(json)$">
    Order allow,deny
    Deny from all
</FilesMatch>
