RewriteEngine On

# 1. Agar URL mein .php, .html, ya .htm ho, toh bina extension ke URL pe redirect kar do (301)
RewriteCond %{THE_REQUEST} \s/([^.]+)\.(php|html|htm)[?\s] [NC]
RewriteRule ^ /%1 [R=301,L]

# 2. Agar requested file/directory nahi hai, lekin .php, .html, ya .htm file exist karti hai, toh serve karo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.htm -f
RewriteRule ^(.*)$ $1.htm [L]

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Only serve files that actually exist
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  # Otherwise redirect all to index.html
  RewriteRule ^ index.html [L]
</IfModule>

