↑ ↓ select, Enter open, Esc close

Redirect Generator

Choose the type of redirect, enter your domain, done: you get the rules for Apache (.htaccess) and for nginx, ready to paste into Plesk.

Generate redirect

Type of redirect
Apache: .htaccess (mod_rewrite)
# Redirect, generated with myline.de/en/tools/redirect-generator/
# Put this in the .htaccess in the document root (Plesk: httpdocs), before the WordPress block.
RewriteEngine On
# A single hop to https://example.com, no chain
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L]
nginx: Additional nginx directives
# Redirect, generated with myline.de/en/tools/redirect-generator/
# Plesk: Apache & nginx Settings, field "Additional nginx directives".
# A single hop to https://example.com, no chain
set $canonical_redirect 0;
if ($scheme != "https") {
    set $canonical_redirect 1;
}
if ($host = "www.example.com") {
    set $canonical_redirect 1;
}
if ($canonical_redirect) {
    return 301 https://example.com$request_uri;
}

Use only one of the two variants. In Plesk with nginx in front of Apache, the nginx rule applies first and the .htaccess is never reached.

Server is clean. Is the site?

How fast does the website really load?

GENLOC.SEO measures PageSpeed and Core Web Vitals on mobile and desktop and tells you clearly what to fix first. Free, no time limit.

by GENLOC.NETWORK, the team behind myline.de

301, 302, 307 or 308: which status code?

CodeMeaningWhen to use
301Moved permanentlyThe default for moves, HTTPS, www and new URLs. Google passes the signals on to the target and after a while only indexes the new URL.
308Permanent, keeps methodLike 301, but a POST stays a POST. Useful for APIs and form endpoints. Equivalent to 301 for Google.
302Found, temporaryShort-term redirects, such as a promotion page. The old URL stays in the index. Leaving a 302 in place permanently sends mixed signals.
307Temporary, keeps methodLike 302, but without changing the method. Browsers also show 307 internally when HSTS kicks in.

Important: browsers often cache 301 and 308 permanently. So test new rules with 302 or with curl first, and only switch to 301 once everything is right. Otherwise, after a fix, you end up chasing an old cache entry.

Avoid redirect chains

A chain happens when a request is redirected more than once, for example http://www.example.com first to https://www.example.com and then to https://example.com. Every hop costs a full network round trip, easily 100 to 300 milliseconds on a first mobile visit. That hurts load time and Core Web Vitals, and Google only follows long chains to a limited extent.

The two combined variants above ("HTTPS and without www" or "with www") check both conditions at once and redirect to the final address in a single hop. Do not add a second HTTPS rule in Plesk or a plugin on top, or the chain comes right back. Also check internal links and the sitemap: they should point directly to the final URL, not to a redirected one.

Test redirects with curl

The browser is a poor testing tool because it caches redirects. curl -I only requests the headers and shows the status code and the target:

curl -sI http://www.example.com/ | grep -iE "^(HTTP|location)"

-L shows the whole chain with every hop. More than one location line means there is a chain.

curl -sIL http://www.example.com/ | grep -iE "^(HTTP|location)"

Only the final result, handy for scripts:

curl -sIL -o /dev/null -w "%{http_code} %{url_effective}\n" http://www.example.com/

Test all four variants of the start address: with and without www, each with http and https. Each one should land on the target address with exactly one hop or directly with 200.

HTTPS redirect in Plesk with a switch

For a plain HTTP to HTTPS redirect you do not need a custom rule in Plesk. Under Websites & Domains, Hosting & DNS, Hosting Settings there is an option for a permanent, SEO-safe 301 redirect from HTTP to HTTPS. Plesk applies it directly in the web server configuration. You make the www decision in the same hosting settings under "Preferred domain". If you set both in the panel, you only need the generator for single URLs, directories and domain moves.

Make sure that the Plesk switches, your own rules and the WordPress settings (Site Address under Settings, General) all use the same target address. If they contradict each other, you get chains or redirect loops.

Common mistakes

  • Redirect loop behind a proxy or CDN: if Cloudflare sits in front in "Flexible" mode, every request reaches the server over HTTP. The rule then keeps redirecting to HTTPS. Fix: SSL mode "Full (strict)" with a valid certificate on the server.
  • Rule placed after the WordPress block: WordPress passes everything to index.php with [L]. Your own redirects therefore belong before # BEGIN WordPress.
  • Query parameters: Apache automatically appends the original parameters to the target, the nginx rules above carry them over with $is_args$args or $request_uri.
  • Redirecting everything to the home page: when moving a site, Google often treats blanket redirects of old URLs to the new home page as soft 404s. Better redirect every important old URL to its matching counterpart.

Bookmark this page: Press Ctrl + D (Mac: ⌘ + D) to have the redirect generator ready for your next domain move or SSL certificate.

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.