mod_rewrite’s syntax is notoriously terse, but a handful of patterns cover the overwhelming majority of real-world rewrite needs.
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Force www (or remove it - pick one, be consistent)
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# Pretty URLs: /products/42 internally maps to /product.php?id=42
RewriteRule ^products/([0-9]+)/?$ product.php?id=$1 [L,QSA]
# Remove .php extension from URLs
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
# Block access to a specific file
RewriteRule ^config\.json$ - [F,L]
[L] stops processing further rules once a match applies (essential to avoid unexpected chained rewrites), and [QSA] appends the original query string to the rewritten URL instead of discarding it — two flags worth memorizing since they appear in almost every real rewrite rule.