Skip to main content

.htaccess Formatter

Format and re-indent Apache .htaccess files. Nested <IfModule>, <FilesMatch>, <Directory> and other sections get consistent indentation and single-spaced directives, with comments and quoted values preserved.

Input

Drop a file or browse
One file · text
Or

Formatting Options

Output

Formatted .htaccess
 
Was this helpful?

Guides

What this tool does

An .htaccess file is a per-directory configuration file for the Apache web server. It controls URL rewriting, redirects, access rules, caching headers, compression, custom error pages and more — all through directives like RewriteRule, Header, ErrorDocument, and section blocks such as <IfModule>, <FilesMatch> and <Directory>. Because .htaccess snippets are so often copy-pasted from tutorials, Stack Overflow answers and plugin READMEs, they quickly become a wall of inconsistent indentation and doubled-up spacing that's hard to scan.

This tool reformats that text into clean, consistently indented configuration: every nested block is indented one level deeper than its parent, directive names are separated from their arguments by a single space, blank-line runs are collapsed to one, and trailing whitespace is trimmed — while comments and quoted values are preserved exactly as written.

It's a line-based formatter, not a full Apache validator. It doesn't check whether a module is loaded or a directive is spelled correctly; it focuses on what actually makes .htaccess files hard to read: indentation and spacing.

How to use it

  1. Paste your .htaccess content into the .htaccess Content box, or upload an existing .htaccess file.
  2. Choose an Indent Size — 2 or 4 spaces per nesting level (2 is the default).
  3. The formatted result appears instantly in the Formatted .htaccess panel. Copy it, or download it as .htaccess.

Formatting runs automatically as you type or edit — there's no button to click.

How the formatting works

The formatter reads your file line by line and tracks a nesting-depth counter. A line that opens a section, like <IfModule mod_rewrite.c>, is emitted at the current depth, then the depth increases for the lines that follow. A closing line like </IfModule> first decreases the depth, then is emitted at that shallower level, so the closer lines up with its opener. Ordinary directive lines are re-indented to the current depth, with runs of whitespace outside quoted strings collapsed to a single space. Comment lines (#...) are only re-indented — the text after the # is never rewritten.

The transform never reorders lines and never changes what a directive means, so running it twice produces exactly the same output (it's idempotent). If a block is left unclosed, or a closer appears with no opener, the tool never errors — depth simply stops decreasing at zero and the rest of the file still formats cleanly.

FAQ

Does this validate my rewrite rules or check syntax? No. It only normalizes indentation and whitespace. Test rules on your server (or a staging copy) before deploying.

Will it change my paths, regex patterns, or quoted values? No. Arguments are left as written, and spaces inside "double-quoted" strings are preserved — only whitespace between separate arguments is collapsed to a single space.

Does it touch my comments? Only to fix indentation and trim trailing spaces. The text after # is left untouched.

Does it work with Nginx configs? No — Nginx uses { } blocks instead of Apache's <Tag>...</Tag> syntax.

Privacy

This tool runs entirely in your browser. Your .htaccess content — including hostnames, paths, and any credentials it may contain — is never uploaded to a server.

htaccessapacheweb serverconfigindentformatter

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.