Build Apache .htaccess redirect rules for individual pages, www/non-www normalization, and forcing HTTPS — copy-paste ready.
This generates Apache mod_rewrite rules wrapped in an <IfModule mod_rewrite.c> block, which is what an .htaccess file needs to force HTTPS, normalize www vs. non-www, strip trailing slashes, or redirect specific old paths to new ones. Each site-wide rule is generated as its own RewriteCond/RewriteRule pair with an [L,R=301] flag — L stops further rule processing once matched, R=301 sends a permanent redirect — while individual page redirects use Apache's simpler Redirect directive instead.
301 means "moved permanently" and tells browsers and search engines to update their records and transfer the old URL's ranking signals to the new one — use it when a page has actually moved for good. 302 means "found" (temporary) and is meant for short-term redirects, like during maintenance, where you don't want search engines to treat the move as permanent.
.htaccess rewrite rules only take effect on Apache servers with the mod_rewrite module enabled and AllowOverride permitting it for that directory. Nginx doesn't read .htaccess files at all — it needs the equivalent rules written directly into its own server block configuration instead.
A malformed rule, or rules that conflict — like forcing both www and non-www at once — can create an infinite redirect loop or make the entire site return a server error, since Apache reads and applies .htaccess on every single request. That's why testing on staging and keeping a backup of the previous working file before replacing it matters more here than for most config changes.