.htaccess Generator

Generate a working Apache .htaccess file: force HTTPS, pick www or non-www, add redirects, set cache headers, block hotlinking and stop directory listings.

Free · no signup · works offline · checked 2026-08-04

HTTPS & hostname
Protection
Performance
Error pages
Redirects one per line: /old /new
.htaccess
Illustration representing Server config.

Why generated rules beat copied ones

Most .htaccess problems come from pasting two snippets that each work alone and fight each other together. The classic is two HTTPS redirects — one from your control panel, one from a tutorial — producing ERR_TOO_MANY_REDIRECTS.

The HTTPS rule here includes a condition most snippets leave out:

RewriteCond %{HTTP:X-Forwarded-Proto} !=https

Without it, any proxy in front of your site — Cloudflare, a load balancer, your host’s edge — terminates TLS, forwards the request as plain HTTP, and your server redirects to HTTPS forever. That one line is the difference between a working redirect and an infinite loop.

Where the file goes

In your web root, next to index.php. Name it exactly .htaccess — with the leading dot and no extension. Some FTP clients hide dotfiles; enable “show hidden files” if you can’t see it.

Rules are inherited. An .htaccess in a parent directory applies to everything beneath it, which is worth remembering when a rule seems to fire on a page you never configured.

If it breaks the site

A bad directive gives you 500 Internal Server Error on every page in that directory and below.

Rename the file rather than deleting it:

mv .htaccess .htaccess.bak

If the site returns, the file is the cause. Restore it and comment out half the rules, reload, and repeat until you find the line. On WordPress, if you deleted the file instead, regenerate the default rules from Settings → Permalinks → Save.

A note on nginx and LiteSpeed

LiteSpeed reads .htaccess natively, so these rules work unchanged. nginx does not read .htaccess at all — if your host runs plain nginx, these rules will be silently ignored and you need the equivalent server block instead. Ask your host which server they run before spending an afternoon debugging a file nothing is reading.