htaccess redirect generator (301, HTTPS, www)

The htaccess redirect generator writes the lines for your .htaccess file: redirect a page or folder, force HTTPS, add or remove www, move a whole domain. A test run shows for a sample URL where the rule sends it. The Nginx equivalent is included.

Source: Apache HTTP Server 2.4 – mod_rewrite (RewriteCond, RewriteRule, Flags R, L, NC). Updated: .

For www rules and domain moves: the domain without www (the old domain when moving).
Path after the domain name, without a query string (?…).
Full URL or a path starting with “/”. For a domain move: the new domain.
Checks the X-Forwarded-Proto header instead of HTTPS because the server itself only sees HTTP.
An address for which the test run shows where the rule sends it.
My ToolboxYour inputs are saved in this browser only.

Result

.htaccess lines
Redirect 301 /alt-seite.html https://example.com/neue-seite/
Browsers and search engines remember 301/308 for a very long time. Test new rules with 302 first and switch to 301 only afterwards. “Redirect” applies to every address that starts with the old path (also /old/subpage). For an exact match choose “RewriteRule”. A query string (?a=b) is passed through unchanged by RewriteRule (Apache default). With Redirect please check on the server. These lines belong at the top of the .htaccess, before existing rules (for example from WordPress), otherwise they may not take effect.
Test run
Result 301 → https://example.com/neue-seite/
Nginx equivalent
location = /alt-seite.html { return 301 https://example.com/neue-seite/; }

How it is calculated

The .htaccess file controls redirects and other rules for a folder and all its subfolders on Apache servers – without touching the server configuration. The generator writes the matching lines; copy them into the root folder of your website.

How to create an htaccess redirect

  1. Under “What should happen?” pick the redirect you need (for example “Redirect a single page” or “Force HTTP → HTTPS”).
  2. Fill in the details – fields you do not need are hidden. For permanent redirects choose “301”.
  3. In the test run enter a sample URL: you see whether and where the rule redirects it.
  4. Copy the lines, paste them into the .htaccess in the root folder and check in a browser (private window).

301 or 302?

A 301 (or 308) says “moved permanently”. Search engines transfer signals to the new address; browsers remember the redirect for a long time. A 302 (or 307) is temporary. Because a 301 is hard to take back, test with 302 first. According to RFC 9110, 307 and 308 – unlike 302 and 301 – do not allow the request method to change.

Redirect or RewriteRule?

Common pitfalls

The test run plays the rule through inside this tool; it does not replace a test on the real server. For Nginx there is a counterpart below the rules (not for every case). Nothing is sent: everything runs in your browser.

Frequently asked questions

How do I create a 301 redirect in .htaccess?

For a single page Redirect 301 /old-path https://example.com/new-path/ is enough. The generator builds the line from your input; it goes into the .htaccess in the root folder.

How do I redirect HTTP to HTTPS?

With mod_rewrite: RewriteCond %{HTTPS} off and RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]. Choose “Force HTTP → HTTPS”; behind Cloudflare or a load balancer also enable “Behind a proxy or CDN”.

How do I redirect www to the non-www domain (or the other way round)?

Choose “With www → without www” or “Without www → with www” and enter the domain. The generator writes the RewriteCond on the host name and the matching RewriteRule.

Where is the .htaccess file?

In the root folder of the website (where the index file lives). It starts with a dot and is invisible at first in some FTP programs – enable “show hidden files”.

What is the difference between 301 and 302?

301 means “moved permanently”, 302 “temporarily”. With 301 search engines transfer the old address’s signals to the new one and browsers remember the redirect for a long time. For trying things out 302 is safer.

Why is my redirect not working?

Often mod_rewrite or AllowOverride is not active, the rule sits behind other rules, the browser shows a cached 301, or a loop occurs (e.g. behind Cloudflare). The test run helps you check the rule itself.

Sources and legal basis

As of:

Related tools