############################################
# FEMTECH WAVES – SECURITY & URL CONTROL
############################################

# Enable Rewrite Engine
RewriteEngine On

############################################
# REMOVE .php EXTENSION FROM URLS
############################################

# Redirect old .php URLs to clean URLs
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?]
RewriteRule ^ %1 [R=301,L]

# Internally map clean URLs to .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [L,NC]

############################################
# FORCE HTTPS
############################################

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

############################################
# DISABLE DIRECTORY LISTING
############################################

Options -Indexes

############################################
# BLOCK ACCESS TO SENSITIVE FILES
############################################

<FilesMatch "\.(env|ini|log|json|lock|sql|bak|yml|yaml)$">
    Require all denied
</FilesMatch>

<FilesMatch "(config|database|db|settings)\.php">
    Require all denied
</FilesMatch>

############################################
# PROTECT .HTACCESS & .HTPASSWD
############################################

<FilesMatch "^\.">
    Require all denied
</FilesMatch>

############################################
# PREVENT PHP EXECUTION IN UPLOADS
############################################

<Directory "uploads">
    php_flag engine off
    Options -Indexes
</Directory>

############################################
# SECURITY HEADERS (REALISTIC & SAFE)
############################################

<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

############################################
# BASIC BOT & BAD REQUEST PROTECTION
############################################

RewriteCond %{HTTP_USER_AGENT} (curl|wget|python|libwww-perl) [NC]
RewriteRule .* - [F,L]

############################################
# CACHE STATIC ASSETS (PERFORMANCE BOOST)
############################################

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType audio/mpeg "access plus 1 year"
</IfModule>

############################################
# GZIP COMPRESSION
############################################

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

############################################
# BLOCK XML-RPC (IF NOT NEEDED)
############################################

<Files xmlrpc.php>
    Require all denied
</Files>

############################################
# END OF FILE
############################################
