.htaccess generator — Apache redirects, HTTPS, caching, and security headers

This free online .htaccess generator helps you assemble common Apache configuration snippets for HTTP to HTTPS redirects, apex versus www canonicalization, 301 URL moves, hotlink protection, mod_expires browser caching and mod_deflate gzip, plus baseline security headers and blocking access to typical sensitive paths. Rules are composed in your browser—you can copy, download, or upload an existing file to edit. After deployment, validate behavior with the redirect chain checker and HTTP header checker, and review TLS with the SSL certificate checker.

Core behavior
Security & access
Performance & headers
301 redirects

From path (e.g. /blog/old) and target URL or path. Empty rows are ignored.

  • No redirect rows.

Defaults: HTTPS, cache, gzip, headers, UTF-8, block .env/.git, no directory indexes.

Why use an .htaccess file for Apache hosting?

On Apache, .htaccess lets you override server behavior per directory when AllowOverride allows it. That is ideal on shared hosting where you cannot edit the main virtual host file. Teams also commit a root .htaccess so redirects and caching travel with the site. This page targets Apache 2.4 patterns (Require all denied, mod_rewrite, mod_headers)—always confirm module availability on your host.

Search intent around htaccess redirect 301, force SSL htaccess, redirect www to non-www, and disable directory listing maps to concrete toggles here. For policy headers that belong at the edge or load balancer, compare output with a CSP or CDN dashboard—the URL encoder can help when you embed long query strings in rules or tests.

How to use this .htaccess generator (step by step)

  1. Set HTTPS, www preference, and whether to strip trailing slashes. Enter your real hostname in primary host before enabling hotlink protection.
  2. Choose security options: block common .env and .git exposure, turn off directory indexes, and add optional security headers (frame options, nosniff, referrer policy).
  3. Tune performance: gzip via mod_deflate, asset caching via mod_expires, and UTF-8 charset. Add an optional ErrorDocument 404 path if your stack uses a static error page.
  4. Add 301 rows for migrations. Use Upload to load an existing file, edit in the preview, then Copy or Download. Reset to form reapplies the current form state if you edited manually.

Keywords and topics this generator covers

The output touches mod_rewrite, mod_alias fallbacks when rewrite is off, mod_headers, mod_expires, and mod_deflate behind <IfModule> guards so missing modules do not always fatal-error. For PEM inspection unrelated to Apache but common in the same workflows, use the SSL certificate decoder and for signing experiments the RSA key pair generator.

Migrations, SEO, and redirect testing

When you move content, search engines care that 301 redirects point to the canonical URL and that HTTPS and host variants converge. After you ship an .htaccess, re-check status codes from both HTTP and HTTPS, and from www and non-www variants. Our redirect chain checker surfaces hop counts—long chains dilute PageRank and slow navigation. Pair with the canonical tag checker when HTML-level canonicals must agree with server redirects.

Related security and encryption tools

Browse the full security and encryption tools catalog. Highlights:

  • Password Strength MeterScore password entropy, estimate crack time, and get practical hardening tips.
  • bcrypt Hash GeneratorGenerate bcrypt hashes with configurable cost for secure password storage testing.
  • AES Encrypt & DecryptEncrypt and decrypt text with AES-256 and a passphrase—runs fully in your browser.
  • RSA Key Pair GeneratorCreate 1024–4096 bit RSA public/private key pairs locally for demos and dev workflows.
  • CSP BuilderToggle Content-Security-Policy directives and copy a header value ready for your server.
  • Security Headers CheckerAnalyze security-related HTTP headers on any URL with graded guidance to harden responses.
  • JWT EncoderBuild HS256-signed JWTs from custom header and payload for API and auth testing.
  • HMAC GeneratorCreate HMAC-SHA256 or HMAC-SHA512 signatures with a secret for webhook and API verification.
  • SSL Certificate DecoderPaste PEM certificates to read subject, issuer, SANs, and validity windows.

Frequently asked questions

What is an .htaccess file and when do I need it?
An .htaccess file is a per-directory configuration file used by Apache HTTP Server. It can enable redirects, HTTPS, caching, access control, and custom headers without editing the main server config. You need it when you host on shared hosting or want portable rules checked into your repository. It only applies if Apache is your web server and AllowOverride permits these directives.
Does this tool upload my site or .htaccess to your servers?
No. Options are merged into a preview in your browser. Copy and download use local APIs only. If you use Upload, the file is read with the File API in your tab—nothing is sent to us for processing.
Will this work on Nginx or IIS?
No. .htaccess is Apache-specific. Nginx uses server blocks and IIS uses web.config. If you migrate, translate the intent (redirects, TLS, caching) into the correct syntax for that server.
Why force HTTPS before canonical www or non-www rules?
Redirects are easier to reason about when you first normalize the scheme (HTTP to HTTPS), then the hostname. The generator follows that order. Test with your real domain and a redirect checker after deploy.
Hotlink protection blocked my own images—what happened?
Hotlink rules compare the Referer header to your primary hostname. If you load assets from a different domain or CDN, add that hostname to your server config manually or adjust the rule. Empty referrers are often allowed for direct navigation; some browsers omit referrers for privacy.
How do I fix a 500 error after pasting generated rules?
A 500 usually means a syntax error or a directive your host disallows. Comment out sections to isolate the problem, confirm mod_rewrite and other modules are enabled, and check that Options +FollowSymLinks is permitted. Shared hosts sometimes restrict Header, Expires, or RewriteBase.
Can I combine this with WordPress or Laravel?
Yes, but merge carefully: frameworks often ship their own .htaccess (for example WordPress front-controller rules). Place framework-required rules first unless documentation says otherwise, then add redirects and security headers. Always back up before editing production.
What tools pair well with testing redirects and headers?
After deployment, use this site’s redirect chain checker and HTTP header checker on your URLs to confirm status codes and response headers. For PEM certificates and TLS inspection, the SSL certificate checker and SSL certificate decoder help validate what visitors receive.