Which status code?
- 301 (Moved Permanently): the default for pages and domains that moved for good. Search engines adopt the new URL; browsers may cache the redirect for a long time.
- 308 (Permanent Redirect): also permanent, but the request method and body are kept — a POST stays a POST. nginx supports 308 from version 1.13.0.
- 302 (Found): temporary, for example maintenance, tests or seasonal pages. The old URL stays in the index.
- 307 (Temporary Redirect): temporary, and the method is kept.
Rule of thumb: 301 for pages and domains that moved permanently, 308 for forms and API endpoints. With 301 and 302, browsers usually turn a POST into a GET.
nginx and Apache compared
- nginx has no
.htaccess. The rules live in the server configuration; after a change runnginx -tand reload.returnis the simplest and fastest form;ifonly makes sense where it contains areturn(for example for X-Forwarded-Proto). - Apache reads
.htaccessonly ifAllowOverridepermits it (FileInfois enough for mod_rewrite) and mod_rewrite is enabled. The vhost configuration is faster.Redirect(mod_alias) matches the path and everything below it;RewriteRuleis more flexible. Do not mix both for the same URL.QSDneeds Apache 2.4.0 or later. - Query string: with
returnnginx does not append it automatically (use$request_urior$is_args$args); Apache keeps it as long as the target has no query of its own (QSAappends,QSDdrops). - Plesk: nginx directives go into Domains → your domain → Apache & nginx Settings → Additional nginx directives, only the lines inside the server block. A
mapbelongs in the http context. For simple cases Plesk has its own options in the hosting settings (preferred domain, HTTP to HTTPS redirect).
Common mistakes
- Loops: the target leads back to the source — for example www → non-www in the web server, but non-www → www in the CMS or CDN. Behind a proxy that terminates TLS, HTTP → HTTPS without checking
X-Forwarded-Protonever ends. - Chains: A → B → C costs a request and time per hop, and crawlers follow only a limited number of redirects. Always point to the final URL.
- Everything to the home page: search engines treat that as a soft 404. Better the page that really matches, otherwise 410 or 404.
- Mixing www and non-www: canonical tags, sitemap and internal links should already use the target host.
- Forgetting the query string: parameters such as
?utm_source=…or?id=7get lost. - 302 instead of 301 for a permanent move — or 301 while still testing: browsers remember it.
Testing and short FAQ
With curl -sI -L --max-redirs 5 URL you see every hop. Look at the status line (for example HTTP/2 301), the location: header (it must match your target exactly) and that the last hop returns 200. More than one redirect in front of it is a chain; curl: (47) Maximum (5) redirects followed means a loop. In a browser the cache can mislead you — test in a private window or with curl.
Can I mix 301 and 308? Yes, search engines treat both as permanent. How long should a redirect stay? At least a year, better as long as the old URL still gets visitors or links. Does location = /old also match /old/? No, an exact match applies to exactly that path.
Privacy
Runs entirely in your browser; nothing is sent or stored.