.htaccess Generator

Build a correct Apache .htaccess file in your browser — force HTTPS or www, add 301 redirects, enable gzip and caching, set error pages, and lock down .ht files. Copy or download it.

Generator Web Development Updated Jun 14, 2026
Learn how this works
How to Use
  1. Tick the options you need — force HTTPS, force www or non-www, disable directory browsing, gzip, caching, and more.
  2. For redirects, fill the old-domain / new-domain fields or a single from-path to-URL pair; lines appear only when the inputs are filled.
  3. Set a custom 404 path if you have an error page (e.g. /404.html).
  4. Watch the output update live in the preview pane as you change options.
  5. Click Copy to grab the text, or Download to save a ready-to-upload .htaccess file.
  6. Upload the file to the folder it should govern — usually your site root — and test the affected URLs.
Options
.htaccess

Upload this to the folder it should govern — usually your site root. Test on a staging copy first.

What this generator does

An .htaccess file is Apache's per-directory configuration file. Drop one in a folder and the web server reads it on every request, applying the directives it contains — redirects, compression, caching, access control, and error pages. Writing those directives by hand is error-prone: a single misplaced character can break a site or cause a redirect loop, and the syntax for mod_rewrite in particular is famously fiddly. This generator assembles vetted, standard blocks for the most common needs so you can tick a box instead of memorizing the rules.

Everything is built entirely in your browser as you change options — nothing is uploaded, and the Download button writes the file locally. Each block is wrapped in a comment header so the finished file stays readable, and the rewrite engine is switched on exactly once at the top whenever any rewrite-based rule (force HTTPS, www / non-www, or an old-domain move) is in use. The output updates live so you can see precisely what each option adds.

Common directives reference

RewriteEngine On
Enables mod_rewrite — emitted once, at the top.
RewriteCond / RewriteRule
Match a request, then rewrite or redirect it.
[L,R=301]
Last rule for this pass; permanent (301) redirect.
Redirect 301 /old /new
Simple permanent redirect via mod_alias.
Options -Indexes
Disable automatic directory listings.
ErrorDocument 404
Serve your own page for not-found URLs.
mod_deflate
Gzip-compress text, CSS, JS, and fonts.
mod_expires
Add browser-cache expiry headers for assets.

Test before you deploy

A broken .htaccess can take a whole site down with a 500 error, so always keep a backup of the existing file and test changes on a staging copy first. Watch for redirect loops — a rule that points a URL back at itself — and remember the order of rules matters because a rule ending in [L] stops Apache processing later ones in that pass. The rewrite blocks here require mod_rewrite; gzip, caching, and headers require mod_deflate, mod_expires, and mod_headers respectively. Most shared hosts enable all of these, but if a block seems ignored, confirm with your host which modules are loaded and whether AllowOverride permits the directive. When you are done here, pair this with the robots.txt Generator and check redirect targets against the HTTP Status Codes reference.

About the .htaccess Generator

.htaccess Generator is a quick, free tool for web development and data tasks. It works in your browser and keeps everything on your device. Build a correct Apache .htaccess file in your browser — force HTTPS or www, add 301 redirects, enable gzip and caching, set error pages, and lock down .ht files. Copy or download it.

How it works

Pick your options and the tool makes the result right away. Do not like it? Make another one — you can do this as many times as you want. When it looks right, copy it into your own project. Everything is made on your device, so it is yours alone.

Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.

Frequently Asked Questions

What is an .htaccess file?

It is a per-directory configuration file for the Apache web server. When Apache serves a request, it reads the <code>.htaccess</code> file in the target folder (and parent folders) and applies the directives it finds — redirects, access rules, compression, caching, and more. The leading dot makes it a hidden file on most systems, and the name has no extension. It only works on Apache (or servers that emulate it like LiteSpeed); Nginx and IIS use a different mechanism.

Where do I put the .htaccess file?

Place it in the directory you want it to control. For site-wide rules that is your document root — the same folder as your <code>index.php</code> or <code>index.html</code>, often called <code>public_html</code> or <code>www</code>. Rules cascade down into subfolders, and a deeper <code>.htaccess</code> can override a shallower one. For the server to honour the file, the Apache config must allow overrides for that directory (the <code>AllowOverride</code> setting).

What is the difference between a 301 and a 302 redirect?

A <strong>301</strong> is a permanent redirect: it tells browsers and search engines the resource has moved for good, so they should update bookmarks and pass link equity to the new URL. A <strong>302</strong> is temporary — the original URL should keep being used in future. For domain moves, HTTPS upgrades, and renamed pages you almost always want 301. This generator emits 301 redirects (<code>R=301</code>) for that reason.

Do redirects require mod_rewrite?

The rewrite-based blocks (force HTTPS, www / non-www, old-domain move) need Apache's <code>mod_rewrite</code> module enabled, and that is what <code>RewriteEngine On</code> switches on. The simple <code>Redirect 301 /old /new</code> line and the gzip, caching, and access blocks use other modules (<code>mod_alias</code>, <code>mod_deflate</code>, <code>mod_expires</code>, <code>mod_headers</code>). Most shared hosts enable all of these; if a block is ignored, ask your host which modules are active.

What are the most common .htaccess mistakes?

Emitting <code>RewriteEngine On</code> more than once (only the first matters, but duplicates are confusing), forgetting that a redirect loop happens when a rule points back at itself, and mis-ordering rules so an early <code>[L]</code> stops later ones. Watch escaping too: in a <code>RewriteRule</code> pattern a literal dot should be written <code>\.</code> and special characters matter. This tool uses vetted, standard snippets to avoid those traps, but always test on a staging copy before going live.

Does .htaccess work on Nginx?

No. <code>.htaccess</code> is an Apache feature and Nginx ignores it entirely. Nginx achieves the same things — redirects, gzip, caching, access control — but with directives inside its own <code>server</code> and <code>location</code> blocks in <code>nginx.conf</code>, applied when the server reloads rather than per-request. If you are on Nginx you will need to translate these rules into that syntax instead.

How do I use the .htaccess Generator?

Just pick your options. The answer shows up right away — there is no button to press. Change anything and it updates by itself.

Does it cost anything or need an account?

No. The tool is completely free, there is no account to create, and it keeps working offline after the page first loads.

Is anything I type uploaded?

No. The tool works entirely on your device, so the values you enter never leave your browser.

Common Use Cases

Force HTTPS site-wide

Redirect every http:// request to https:// with a permanent 301 so visitors and search engines always land on the secure version.

Pick one canonical hostname

Force www or non-www consistently to avoid duplicate-content issues and split analytics across two hostnames.

Migrate to a new domain

Send every path on an old domain to the matching path on a new one with a single rewrite block, preserving SEO value.

Fix moved or renamed pages

Add 301 redirects from old URLs to new ones so old links and bookmarks keep working after a restructure.

Speed up your site

Turn on gzip compression and browser-cache expires headers to cut page weight and repeat-visit load times.

Harden a directory

Disable directory listings, block access to .ht files, and stop image hotlinking to protect content and bandwidth.

Last updated: