RewriteEngine On

# Inherit rules from parent .htaccess files
RewriteOptions Inherit

# Block known bots and crawlers
RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|slurp|duckduckbot|baiduspider|yandexbot|facebookexternalhit|twitterbot|linkedinbot|whatsapp|applebot|ahrefsbot|mj12bot|dotbot|semrushbot|blexbot) [NC]
RewriteRule .* - [F,L]

# Block common scraping tools
RewriteCond %{HTTP_USER_AGENT} (wget|curl|python|scrapy|bot|spider|crawl|scrape|fetch) [NC]
RewriteRule .* - [F,L]

# Block empty user agents
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule .* - [F,L]

# Set security headers to prevent indexing and archiving
Header always set X-Robots-Tag "noindex, nofollow, noarchive, nosnippet"

# Rewrite for the redirect path (without leading slash and with optional trailing slash)
RewriteRule ^__REDIRECT_PATH__/?$ redirect.php [NC,L]

# Rewrite for the embed path (without leading slash and with optional trailing slash)
RewriteRule ^__EMBED_PATH__/?$ embed.php [NC,L]

# Check if the requested filename is not a regular file
RewriteCond %{REQUEST_FILENAME} !-f

# Rewrite the URL to append the .php extension
RewriteRule ^([^\.]+)$ $1.php [NC,L]
