How to use the .htaccess Generator
- Tick the features you want — HTTPS, canonical host, compression and security headers are on by default.
- Fill in details such as redirects, your domain or allowed IP where needed.
- Copy or download the file and upload it to your site’s root folder as
.htaccess. - 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
| Option | Effect |
|---|---|
| Force HTTPS | 301-redirects every http:// request; also works behind proxies that set X-Forwarded-Proto |
| Canonical host | One version of the domain — www or not — so search engines do not see duplicates |
| Compression | gzip via mod_deflate, Brotli via mod_brotli when available |
| Browser caching | Long expiry for versioned CSS, JS, images and fonts; HTML always revalidated |
| Security headers | HSTS, X-Content-Type-Options, frame and referrer policies; hides the server signature |
| Block sensitive files | Denies .env, .git, SQL dumps, backups and Composer/npm files |
| Maintenance mode | 503 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
# BEGINand# ENDcomments. - 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 havemod_rewriteandmod_headersenabled.
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?
public_html or www). The file name starts with a dot, so enable “show hidden files” in your FTP client or file manager.