RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force www to non-www (or vice versa — pick one)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# SEO-friendly page URLs
RewriteRule ^conditions/?$ index.php?p=conditions [L,QSA]
RewriteRule ^analysis/?$ index.php?p=analysis [L,QSA]
RewriteRule ^products/?$ index.php?p=products [L,QSA]
RewriteRule ^contact/?$ index.php?p=contact [L,QSA]
RewriteRule ^vaginal-tightening/?$ index.php?p=home [L,QSA]
RewriteRule ^vaginal-tightening-assessment/?$ index.php?p=analysis [L,QSA]
RewriteRule ^vaginal-health-products/?$ index.php?p=products [L,QSA]

# Block access to sensitive files
RewriteRule ^config\.php$ - [F,L]
RewriteRule ^setup\.php$ - [F,L]

# Block directory browsing
Options -Indexes

# 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"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Block access to uploads directory listing
<IfModule mod_autoindex.c>
    Options -Indexes
</IfModule>

# PHP settings for file uploads
<IfModule mod_php.c>
    php_value upload_max_filesize 100M
    php_value post_max_size 200M
    php_value max_execution_time 120
    php_value max_input_time 120
</IfModule>

# Gzip compression for speed
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json
</IfModule>

# Cache static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>
