.htaccess Generator for Apache

Tick the rules you need — HTTPS, canonical host, redirects, compression, caching, security headers, protected files — and get a clean, commented .htaccess file.

Runs in your browserUpdated

URLs & redirects

Performance

Security

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the .htaccess Generator

  1. Tick the features you want — HTTPS, canonical host, compression and security headers are on by default.
  2. Fill in details such as redirects, your domain or allowed IP where needed.
  3. Copy or download the file and upload it to your site’s root folder as .htaccess.
  4. Click Test rules to simulate URLs against the generated rewrite rules.

What is .htaccess?

An .htaccess file is a per-directory configuration file for the Apache web server (and LiteSpeed, which reads the same syntax). It is how most shared hosting, WordPress and PHP sites configure redirects, URL rewriting, caching, compression and access control without touching the main server configuration. Rules apply to the folder the file is in and all subfolders.

What each option does

OptionEffect
Force HTTPS301-redirects every http:// request; also works behind proxies that set X-Forwarded-Proto
Canonical hostOne version of the domain — www or not — so search engines do not see duplicates
Compressiongzip via mod_deflate, Brotli via mod_brotli when available
Browser cachingLong expiry for versioned CSS, JS, images and fonts; HTML always revalidated
Security headersHSTS, X-Content-Type-Options, frame and referrer policies; hides the server signature
Block sensitive filesDenies .env, .git, SQL dumps, backups and Composer/npm files
Maintenance mode503 with Retry-After for everyone except your IP — the SEO-safe way to go offline

Before uploading

  • Keep a copy of your existing file — WordPress and other CMSs add their own block between # BEGIN and # END comments.
  • A syntax error makes the whole site return 500 Internal Server Error. Check the file with the .htaccess tester first.
  • Test redirects in a private window — browsers cache 301 redirects aggressively.
  • Your host must allow overrides (AllowOverride All) and have mod_rewrite and mod_headers enabled.

On Nginx, .htaccess files are ignored — use the Nginx config generator. For many individual redirects, the redirect generator outputs Apache, Nginx and other formats; check the result live with the redirect checker.

Tools that pair well with the .htaccess Generator

  • Htpasswd Generator — Generate user:hash lines for HTTP Basic Authentication in Apache, Nginx, Traefik and Caddy — with bcrypt by default and nothing sent to a server.
  • .gitignore Generator — Tick your stack — Node, Python, React, Next.js, Docker, macOS, VS Code and 40 more — and get one clean, de-duplicated .gitignore with commented sections, ready to download.
  • Git Command Generator — Pick a task like “undo the last commit but keep my changes” or “rename a branch on GitHub”, fill in your branch names and get the exact Git commands — each line explained, risky steps flagged.
  • package.json Generator — Fill in a form and get a valid package.json — npm name validation, script presets for Vite, Next.js, Node and TypeScript libraries, exports, engines, license and repository — with warnings for common mistakes.

Frequently asked questions

Where do I put the .htaccess file?
In your website’s document root (often public_html or www). The file name starts with a dot, so enable “show hidden files” in your FTP client or file manager.
Why does my site show a 500 error after editing .htaccess?
Apache found a syntax error or a directive that is not allowed. Restore the previous file, then check the new one in the .htaccess tester.
Does .htaccess work on Nginx?
No. Nginx ignores .htaccess files; the same rules must be written in the server block.
Is a 301 redirect good for SEO?
Yes. A 301 tells search engines the move is permanent and passes ranking signals to the new URL.

Related tools