Build the .htaccess rules for redirects, forcing HTTPS and settling on www or non-www. The detail that matters is escaping: RewriteRule patterns are regular expressions, where a dot means any character — so an unescaped rule for /about.html also catches /about1html and quietly redirects URLs you never meant to touch. Literal paths here are escaped and anchored so they match exactly what you typed. Rules are also checked for the mistakes that are hard to see: a path redirecting to itself, two rules matching the same source where only the first can ever run, and wildcards in a rule not marked as a regular expression. Back up your existing file before replacing it — a syntax error in .htaccess returns a 500 for the entire site, not just the broken rule.
| Code | Meaning | Method preserved |
|---|---|---|
| 301 | Permanent — passes ranking, cached hard | Not guaranteed |
| 302 | Temporary — original stays indexed | Not guaranteed |
| 307 | Temporary | Yes |
| 308 | Permanent | Yes |
301 for a permanent move: it passes ranking signals to the new URL and tells search engines to update their index. 302 for something temporary, where you want the original URL to stay indexed. Be careful with 301 — browsers cache it hard, so anyone who has already followed a mistaken one keeps being redirected even after you fix the file.
Because the pattern is a regular expression. A dot matches any character, so /about.html also matches /about1html. Literal paths are escaped automatically here; switch a rule to regular-expression mode only when you actually want pattern matching.
Because RewriteRule matches against the path relative to the directory the .htaccess sits in, with the leading slash already removed. A pattern starting with a slash matches nothing — a rule that looks right and does nothing. Leading slashes are stripped for you.
It makes a server without mod_rewrite skip the block instead of failing. Without it, a rewrite directive on a server that does not understand it returns a 500 for every request to the site.
308 guarantees the request method is preserved. Historically some clients turned a POST into a GET when following a 301, which breaks form submissions. For ordinary page redirects 301 is fine and better understood; use 308 where the method matters.
A syntax error anywhere in .htaccess takes down the whole site, not just the offending line. Restore your backup, then reintroduce rules a few at a time. This is exactly why the file should be backed up before it is replaced.
RewriteRule patterns are regular expressions, and the single most damaging consequence is that a dot means 'any character'. A rule written for /about.html without escaping also matches /about1html and /aboutxhtml — URLs the author never intended to touch, silently redirected. Literal paths entered here are escaped and anchored with ^ and $ so they match exactly what was typed and nothing else, while a rule explicitly marked as a regular expression is passed through untouched. Leading slashes are stripped because a RewriteRule pattern in .htaccess is matched against the path relative to the directory, so a pattern beginning with a slash never matches anything — a rule that appears correct and does nothing. The generated file is wrapped in an IfModule guard so a server without mod_rewrite ignores it rather than returning a 500 for every request. Rules are also checked for the failures that are hard to spot by eye: a path redirecting to itself, which is an infinite loop; two rules matching the same source, where only the first will ever run; and wildcard characters in a rule not marked as a regular expression, which will be matched literally. The status codes are explained rather than listed, because 301 is cached aggressively by browsers and a mistaken permanent redirect keeps firing for anyone who has already received it, long after the file is fixed.