Skip to content

.htaccess Redirect Generator

Build Apache .htaccess redirect rules with 301/302 status, force HTTPS, www or non-www, trailing-slash fixes, custom path redirects, and optional HSTS. Everything runs in your browser — nothing is sent to a server.

.htaccess generator controls

Redirect type

HTTPS

www host

www and non-www are mutually exclusive — pick one canonical host.

Trailing slash

HSTS (optional)

Enable HTTPS first in production before long HSTS max-age values.

Custom redirects (from → to)

One rule per line: /old /new or /path https://example.com/target. Lines starting with # are comments.

How it works

Choose a redirect status (301 or 302), then toggle the host and path behaviors you need: force HTTPS, force www or non-www, and normalize trailing slashes. Add optional custom from → to lines for one-off path moves or external targets.

The generator assembles a ready-to-paste .htaccess snippet: it turns on RewriteEngine when rewrite rules are present, wraps rules in mod_rewrite guards, and emits Header always set for HSTS when enabled (via mod_headers).

Output updates live as you change options. Use Load sample for a realistic starter, Copy to clipboard, then Clear when you are done. Nothing is uploaded — rules are built only in this tab.

When to use this tool

Tips

Frequently asked questions

What is an .htaccess redirect?

An .htaccess file lets Apache apply per-directory rules, including RewriteRule redirects. Common uses are permanent (301) or temporary (302) URL moves, forcing HTTPS, choosing www vs non-www, and fixing trailing slashes.

301 vs 302 — which should I use?

Use 301 when the change is permanent (SEO signals should move to the new URL). Use 302 for temporary moves or A/B tests. Search engines treat them differently; prefer 301 for lasting renames.

Does my configuration leave my browser?

No. This generator runs entirely in your browser with JavaScript. Nothing is uploaded to a server.

Is this .htaccess redirect generator free?

Yes. The Formattly .htaccess Redirect Generator is free to use with no signup required.

Do I need mod_rewrite and mod_headers?

Yes for most rules here: RewriteEngine and RewriteRule need mod_rewrite. The optional Strict-Transport-Security header uses Header set via mod_headers. Confirm both modules are enabled on your host before deploying.