DirectoryIndex index.html
Options -Indexes -MultiViews
AddDefaultCharset utf-8
<IfModule mod_mime.c>
  AddType text/html .html .htm
</IfModule>
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
</IfModule>
RewriteEngine On

# Rule 1: Redirect 301 permanent to canonical host only
# HTTPS redirect is handled by Cloudflare "Always Use HTTPS"
# Only redirect if host is wrong (don't check HTTPS since Cloudflare handles it)
# [L] flag stops processing, so new request will come in after redirect
RewriteCond %{HTTP_HOST} !^www\.guruyes\.com$ [NC]
RewriteRule ^(.*)$ https://www.guruyes.com/$1 [L,R=301]

# Allow direct access to existing files (skip rewrite if file exists)
# This includes index.html files in subdirectories
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rule 3: For URLs ending with / - serve corresponding .html file even if directory exists
# e.g., /about/ -> /about.html (if about.html exists)
# Excludes homepage (/) to avoid conflict with Rule 2
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{DOCUMENT_ROOT}%1\.html -f
RewriteRule ^(.+)/$ /$1.html [L]

# Rule 4: For URLs without extension - serve corresponding .html file
# e.g., /about -> /about.html (if about.html exists)
# Excludes homepage (/) to avoid conflict with Rule 2
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/(.+?)$
RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
RewriteRule ^(.+?)$ /$1.html [L]

