Write .htaccess rules without memorizing syntax

HTTPS redirect, www canonicalization, custom error pages, and caching headers — compose them into a valid Apache .htaccess file.

Tools used in this guide

The job

Shared Apache hosts still take per-directory config through .htaccess. The mod_rewrite syntax is famously finicky — a missing [L] or a wrong flag changes behavior silently. The generator emits tested patterns for the usual cases.

Toggle the rules you need

Check the blocks you want: force HTTPS, redirect www↔non-www, custom error documents, 301 redirect lines, caching hints, or the directory-listing switch. Each block emits the standard, commented lines. Download or copy the file.

  • The rewrite rules use %{HTTP_HOST}, so they work on any domain without hard-coding yours.
  • The tool offers one canonical host direction; forcing both directions on a server would loop.

Worked example

HTTPS redirect plus non-www canonicalization emits a RewriteEngine On block, a %{HTTPS} off condition, a www-stripping condition, and 301 rules — ready to drop in the docroot.

Where it stops

Apache 2.4 syntax only — no nginx, Caddy, or IIS. It composes common blocks, not arbitrary rules; complex rewrites need hand-editing. Always test on staging first: a bad .htaccess can take a whole site to 500.