.htaccess Generator

Build Apache redirect, HTTPS, canonical, and caching rules — with source paths escaped correctly.

Redirects

Canonical URLs

Extras

.htaccess
1
2
3
4
5
6
7
8
9
10
11
12
  • Back up your existing .htaccess before replacing it — a syntax error takes the whole site down with a 500.
  • Rules apply in order, and the [L] flag stops processing, so put redirects before catch-all rules.
  • .htaccess is Apache-only and is read on every request. If you control the server config, the same rules are faster in the vhost.

Your Data Never Leaves Your Device

Every tool runs entirely in your browser. Nothing you type is uploaded, stored, or logged on our servers.

100% Client-Side

The .htaccess Generator produces Apache rules for the things people reach for during a site migration: 301 and 302 redirects, 410 responses for deleted pages, forcing HTTPS, canonicalising www, and normalising trailing slashes, plus optional compression and caching blocks.

The detail that matters most is escaping. A RewriteRule pattern is a regular expression matched against the path without its leading slash, so a hand-written rule for /page.html silently matches more than intended because the dot is a wildcard. Source paths here are escaped and the leading slash stripped automatically. The compression and caching blocks are wrapped in IfModule guards so a server without those modules degrades quietly rather than returning a 500 — which is also why you should back up your existing file before replacing it.

FAQ

301 for a permanent move — it transfers ranking signals to the new URL and browsers cache it hard, which makes mistakes painful to undo. 302 for anything temporary, such as a maintenance page or an A/B test.

A RewriteRule pattern is matched against the path without its leading slash, and it is a regular expression, so a literal dot in something like /page.html must be escaped. This tool strips the slash and escapes the pattern for you.

410 Gone tells crawlers the content was deliberately removed and is not coming back, which gets it dropped from the index faster than a 404. Use it when you delete a page with no replacement.

Almost always a syntax error or a module that is not enabled. Rename the file to confirm it is the cause, then re-add rules a block at a time. The IfModule wrappers here guard the compression and caching blocks for exactly this reason.

Apache evaluates rules top to bottom, and the [L] flag stops processing on a match. A broad catch-all placed above a specific redirect will swallow it, so put specific rules first.

If you control the server configuration, put the same directives in the vhost instead — Apache re-reads .htaccess on every request, in every parent directory. Use .htaccess when shared hosting gives you no alternative.