Skip to main content

.htaccess Rule Generator

Generate a ready-to-use Apache .htaccess snippet by toggling common rules: force HTTPS, www/non-www canonicalization, disable directory listing, block sensitive files, prevent image hotlinking, a custom 404 page, gzip compression and browser caching.

Input

Redirects & canonicalization

Security

Error pages

Performance

Output

Generated .htaccess
 
Was this helpful?

Guides

The .htaccess Rule Generator builds a ready-to-paste Apache configuration snippet from a handful of checkboxes and inputs. Instead of hunting down and hand-editing rewrite rules, you toggle the behaviors you want — force HTTPS, redirect www, block sensitive files, add caching — and the tool assembles one clean, commented .htaccess file for you.

What is a .htaccess file?

.htaccess is a per-directory configuration file read by the Apache web server. When present in a folder, it lets you change how the server responds to requests for that folder and everything below it — without touching the main server config. It is the standard way to add redirects, tighten security, enable compression, and set caching headers on shared hosting, cPanel, and most WordPress or PHP setups.

Because the file is read on every request, a single typo can take a whole site offline with a 500 error. Generating rules from tested templates avoids the most common syntax mistakes.

How to use this tool

  1. Toggle the rules you want. Sensible security defaults (force HTTPS, disable directory browsing, deny access to dotfiles) are pre-selected.
  2. Fill in any rule-specific values — the allowed domain for hotlink protection, your custom 404 page path, or the cache lifetime in days.
  3. The combined snippet updates automatically. Copy it or download it as a .htaccess file.
  4. Upload the file to the directory you want it to govern (usually your site's web root).

Always keep a backup of your existing .htaccess before replacing it, and add new rules at the top of the file so they run before any application-generated rules (for example, WordPress's own rewrite block).

Which rules can it generate?

  • Force HTTPS — 301-redirects every HTTP request to HTTPS.
  • www canonicalization — redirect www to non-www, or the reverse, so search engines see one canonical host.
  • Disable directory browsing — hides the auto-generated file listing Apache shows for folders without an index file.
  • Deny sensitive files — blocks direct web access to .env, .git, .htaccess, and similar dotfiles.
  • Prevent image hotlinking — stops other sites from embedding your images while still allowing your own domain and direct visits.
  • Custom 404 page — points not-found errors at a page you design.
  • GZIP compression — shrinks text, CSS, and JavaScript responses for faster loads.
  • Browser caching — sets Expires headers so returning visitors reuse cached assets.

Frequently asked questions

Does this work on Nginx? No. .htaccess is an Apache feature. Nginx uses a different configuration format and ignores these files.

Will these rules break my WordPress site? They are designed to coexist with WordPress. Paste the generated rules above the # BEGIN WordPress block. The HTTPS and www redirects are the ones to test first, since a wrong choice can cause a redirect loop.

Why is each rule wrapped in <IfModule>? Rewrite, compression, and expiry directives depend on Apache modules (mod_rewrite, mod_deflate, mod_expires) that may not be enabled on every host. The <IfModule> guard makes the file safe to deploy even where a module is missing — the rules are simply skipped instead of throwing a server error.

Is my input sent anywhere? No. The snippet is generated entirely in your browser. Nothing you type is uploaded.

htaccessapacheweb serverredirecthttpsgeneratorconfig

Love the tools? Lose the ads.

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