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: .
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
- Under “What should happen?” pick the redirect you need (for example “Redirect a single page” or “Force HTTP → HTTPS”).
- Fill in the details – fields you do not need are hidden. For permanent redirects choose “301”.
- In the test run enter a sample URL: you see whether and where the rule redirects it.
- 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?
- Redirect / RedirectMatch (mod_alias) are simple and enough for pages and folders.
Redirectapplies to every address that begins with the old path. - RewriteRule (mod_rewrite) is needed for conditions like “only if not HTTPS” or “only for this domain”. The query string is passed through unchanged by default.
Common pitfalls
- Order: the redirect must come before general rules (such as WordPress).
- Endless loop: the target must not fall under the rule again; behind a proxy or CDN the HTTPS check must use X-Forwarded-Proto.
- The server must evaluate .htaccess (AllowOverride) and have mod_rewrite enabled.
- Browser cache: after changing a 301 only clearing the cache or a private window helps.
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
- Apache HTTP Server 2.4 – mod_rewrite (RewriteCond, RewriteRule, Flags R, L, NC)
- Apache HTTP Server 2.4 – mod_alias (Redirect, RedirectMatch, Statuswerte permanent/temp/seeother/gone)
- § 15.4: IETF RFC 9110 – HTTP Semantics, § 15.4 Redirection 3xx (301, 302, 303, 307, 308)
- Nginx – ngx_http_rewrite_module (return, rewrite)
As of:
Related tools
- URL slug generatorTurn headlines into clean URL slugs: lowercase, hyphens, accents removed, stop words optional. Paste several titles at once and copy all slugs in one go.
- Base64 Encode and DecodeEncode and decode Base64 and Base64url with proper UTF-8, plus URL encode/decode (percent-encoding). Clear error messages, runs locally in your browser.
- SERP Preview Tool With Pixel WidthEnter a title tag and meta description to preview the search result – with pixel width, character count and a note when the snippet is likely truncated.
- UTM builderAdd UTM parameters to links: utm_source, utm_medium, utm_campaign and more, correctly encoded, existing parameters kept. Campaign URL builder with typo checks.
- Sitemap XML generator: build sitemap.xml from your URL listSitemap XML generator without signup: paste URLs, get a valid sitemap.xml per the Sitemaps protocol, check for errors and download it. Runs in your browser.
- DNS lookupLook up the DNS records of any domain: A, AAAA, MX, TXT, CNAME, NS, SOA, CAA, SRV and PTR – with TTL, DNSSEC status and explained error codes. Free.