# .htaccess for womanizerpath.com
# Talk to Strangers | Omegle Talk to Strangers | Talk to Strangers Online

RewriteEngine On
RewriteBase /

# =====================================================
# FORCE HTTPS & WWW
# =====================================================
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

# =====================================================
# CLEAN URLs
# =====================================================
# Remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]

# Remove .html extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R=301]

# =====================================================
# SEO KEYWORD REDIRECTS
# =====================================================
RewriteRule ^omegle$ /omegle-alternative [R=301,L]
RewriteRule ^sites-like-omegle$ /omegle-alternative [R=301,L]
RewriteRule ^chatroulette$ /random-chat [R=301,L]
RewriteRule ^randomchat$ /random-chat [R=301,L]
RewriteRule ^chat-strangers$ /chat-with-strangers [R=301,L]

# =====================================================
# WEBSOCKET PROXY (if using Apache as reverse proxy)
# =====================================================
# RewriteCond %{HTTP:Upgrade} websocket [NC]
# RewriteCond %{HTTP:Connection} upgrade [NC]
# RewriteRule ^ws/(.*)$ ws://localhost:3000/$1 [P,L]

# =====================================================
# SECURITY HEADERS
# =====================================================
<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    
    # Allow WebSocket connections
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.googletagmanager.com https://www.google-analytics.com https://pagead2.googlesyndication.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; connect-src 'self' wss: https:; frame-src https://googleads.g.doubleclick.net https://www.google.com; frame-ancestors 'self';"
</IfModule>

# =====================================================
# CACHING
# =====================================================
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
    
    ExpiresByType text/html "access plus 1 hour"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/json "access plus 0 seconds"
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(html|htm)$">
        Header set Cache-Control "max-age=3600, public, must-revalidate"
    </FilesMatch>
    <FilesMatch "\.(css|js)$">
        Header set Cache-Control "max-age=31536000, public, immutable"
    </FilesMatch>
    <FilesMatch "\.(ico|jpg|jpeg|png|gif|webp|svg)$">
        Header set Cache-Control "max-age=31536000, public, immutable"
    </FilesMatch>
</IfModule>

# =====================================================
# GZIP COMPRESSION
# =====================================================
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# =====================================================
# ERROR PAGES
# =====================================================
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

# =====================================================
# BLOCK BAD BOTS
# =====================================================
<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_USER_AGENT} (AhrefsBot|SemrushBot|MJ12bot|DotBot|BLEXBot) [NC]
    RewriteRule .* - [F,L]
</IfModule>

# Block sensitive files
<FilesMatch "(^#.*#|\.(bak|conf|dist|fla|in[ci]|log|psd|sh|sql|sw[op])|~)$">
    Require all denied
</FilesMatch>

<Files .htaccess>
    Require all denied
</Files>

# =====================================================
# MIME TYPES
# =====================================================
<IfModule mod_mime.c>
    AddType application/javascript js
    AddType application/json json
    AddType image/svg+xml svg svgz
    AddType image/webp webp
    AddType font/woff woff
    AddType font/woff2 woff2
</IfModule>

# Disable ETags
<IfModule mod_headers.c>
    Header unset ETag
</IfModule>
FileETag None