Skip to content
empinet.dev
Generators & Identifiers

Apache / .htaccess Redirect Generator

Generate Apache 301 or 302 redirect rules for HTTP to HTTPS, www to non-www or the reverse, domain migrations, and individual pages. Build the .htaccess snippet locally and read its behavior before copying it.

Build an Apache redirect

Redirect settings

Redirect type

HTTP status

Use 302 while testing. Browsers may cache 301 redirects.

Source hostname

Hostname only. No scheme, port, or path.

.htaccess snippet

Redirects HTTP requests for example.com to https://example.com, preserving the path and query string. Requires mod_rewrite and a document-root .htaccess with FileInfo overrides. This assumes Apache receives the original connection scheme directly.

Where to put .htaccess redirect rules

Use the source site’s document-root .htaccess, not a nested directory. These rules require Apache 2.4, mod_rewrite, and FileInfo overrides. Page redirects use an anchored, escaped RewriteRule for a literal, exact path. Merge carefully with existing framework and rewrite rules; this output is not a replacement for the whole file. If you control Apache’s virtual hosts, a dedicated redirect virtual host is often simpler than .htaccess.

HTTP to HTTPS and www redirects

HTTPS rules redirect only HTTP requests for the selected hostname. The www option redirects only the non-canonical hostname, in either direction. All hostname redirects use a fixed HTTPS destination and keep the request path and query string. Configure DNS and certificates first, including a certificate for a source hostname that receives HTTPS requests.

Domain moves and exact page redirects

Domain moves match the old hostname and preserve the complete request path, rather than sending every page to the homepage. Page rules match exactly: /old-page does not match /old-page/ or /old-page/child. An incoming query is retained unless the destination URL supplies its own query. The source form accepts simple ASCII paths, not regex, percent-encoded paths, or fragment matching.

301 versus 302 redirects

Choose 301 for a permanent move and 302 for a temporary redirect. Start with 302 while checking for loops, the destination, and query handling; browsers can retain permanent redirects. These statuses are not intended to guarantee preservation of POST methods or bodies. Test with your real request methods before applying a rule to an API.

Cloudflare, reverse proxies, and HTTPS loops

The generated HTTPS condition assumes Apache sees the original connection scheme. When TLS terminates at Cloudflare, a load balancer, or another proxy, that assumption may not hold and a loop can result. Prefer the proxy’s HTTPS redirect settings or a server configuration that trusts only an authenticated, controlled proxy. Do not blindly trust client-supplied X-Forwarded-Proto headers.

Generated snippets, not live validation

The tool validates inputs but does not connect to your server, change files, or detect conflicts with existing rules. Review the normalized output, back up the current config, and test on a staging site. A page destination must not redirect back to the same source URL. Wildcards, bulk imports, TLS setup, and arbitrary rewrite expressions are outside this focused generator.

References: Apache redirect recipes and RewriteRule flags.