RunTheTests
/

.htaccess Rule Generator

Describe the rules you want and get a valid .htaccess block.

What you paste

Parsed in your browser — never uploaded

How this reads your output

Each line you write is matched against a set of known rule shapes and converted into the corresponding Apache directives, with rewrite rules grouped inside a single mod_rewrite block and module-dependent directives wrapped in the matching IfModule guard. Lines that are not recognised are reported rather than silently dropped, so nothing goes missing between what you asked for and what you deploy.

What the results mean

Needs mod_rewrite
Whether the output depends on the rewrite module. It is present on almost every Apache host, and the IfModule guard means the file still loads if it is not.
Lines not recognised
Requests that produced no directives. Check these, because a rule you asked for and did not get is the failure mode that matters.
Rule order
Rewrite rules are evaluated top to bottom and the first match with an L flag stops processing, so order changes behaviour.

Common problems and fixes

The site returns a 500 error after uploading the file
A syntax error, an unsupported directive, or a module that is not loaded. Apache refuses to serve rather than skipping the bad line. Restore the previous file immediately, then reintroduce rules one at a time. The server error log names the exact line, which is far quicker than guessing.
A redirect loops endlessly
Usually an HTTPS redirect behind a proxy or load balancer that terminates TLS. The server sees plain HTTP on every request, so the rule fires forever. Check the X-Forwarded-Proto header instead of the HTTPS variable in that setup. Conflicting www and HTTPS rules produce the same symptom when they redirect to each other.

Frequently asked questions

Is .htaccess slower than server configuration?

Measurably, yes. Apache reads and evaluates it on every request, and for every directory in the path, including for each image on a page. The official documentation recommends main server configuration wherever you have access. On shared hosting you generally do not, which is why .htaccess exists.

Does this work on nginx?

No. nginx has no equivalent per-directory configuration file by design, and these directives mean nothing to it. The same outcomes are configured in the server block and require a reload to take effect.

Should redirects be 301 or 302?

301 for anything permanent, since it passes ranking signals and is cached by browsers, sometimes stubbornly. Use 302 while testing or for genuinely temporary moves. A wrong 301 cached in browsers is unpleasant to undo, so start with 302 if you are unsure.

Put this on your own site

Free to embed, no attribution required beyond the source link the frame carries itself. It runs entirely in your visitor's browser, sets no cookies and loads no third-party script.

Embed code
<iframe src="https://runthetests.com/embed/htaccess-generator/" width="100%" height="720" style="border:1px solid #e5e5e5;border-radius:8px" title=".htaccess Rule Generator" loading="lazy"></iframe>

Preview it at https://runthetests.com/embed/htaccess-generator/. Embedded pages are marked noindex, so yours stays the canonical copy — not this one.

More in DevTools