How It Works
Each section of the form maps to a block of Apache directives in the generated output. Toggle options on or off and the .htaccess code updates instantly. Every generated rule includes a comment explaining what it does, so you can audit the file before deploying it.
- Redirects — generates
Redirect 301orRedirect 302lines for each old-to-new URL pair you add. - Security — toggles produce directives like
Options -Indexes,FilesMatchblocks for .env files,RedirectMatch 404for .git, HTTPS enforcement viaRewriteRule, and hotlink protection. - Caching — enables
mod_expireswith sensible defaults: 1 month for images and fonts, 1 week for CSS/JS, no cache for HTML. - Compression — uses
mod_deflateto Gzip text-based content types (HTML, CSS, JS, JSON, SVG, XML). - Custom rules — a freeform textarea for any directives not covered by the UI.
The entire tool runs client-side — your configuration is never sent to a server. Click Copy to grab the output or Download to save a ready-to-use .htaccess file.
What Is .htaccess?
An .htaccess (hypertext access) file is a directory-level configuration file for the Apache HTTP Server. When Apache processes a request, it checks each directory along the path for an .htaccess file and applies any directives it finds. This lets you override server-wide settings on a per-directory basis without editing the main httpd.conf.
Common use cases include URL redirects, access control, custom error pages, MIME type configuration, caching headers, and URL rewriting. The file must be named exactly .htaccess (with the leading dot) and placed in the directory you want the rules to apply to. Rules cascade into subdirectories unless overridden by another .htaccess file further down the path.
Common .htaccess Directives
| Directive | Purpose | Example |
|---|---|---|
| Redirect | Sends visitors from one URL to another | Redirect 301 /old /new |
| RewriteRule | Rewrites URLs using regex patterns | RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L] |
| Options -Indexes | Disables directory listing | Options -Indexes |
| ErrorDocument | Custom error pages | ErrorDocument 404 /404.html |
| ExpiresByType | Sets caching duration by MIME type | ExpiresByType image/jpeg "access plus 1 month" |
| AddOutputFilterByType | Enables compression per content type | AddOutputFilterByType DEFLATE text/html |
| FilesMatch | Applies rules to files matching a pattern | <FilesMatch "\.env"> |
| Header set | Adds or modifies HTTP response headers | Header set X-Frame-Options "SAMEORIGIN" |
FAQ
Where do I put the .htaccess file?
Place it in the root directory of your website (the same folder as your index.html or index.php). The rules apply to that directory and all subdirectories. If you need different rules for a specific subdirectory, you can add a separate .htaccess file there — it will override the parent rules for that path.
Does this work with Nginx?
No. The .htaccess file is specific to the Apache HTTP Server. Nginx does not read .htaccess files — its configuration is done through server block directives in nginx.conf. If you are on Nginx, you will need to translate these rules into the equivalent Nginx syntax. Many hosting providers that use Apache (shared hosting, cPanel, etc.) support .htaccess out of the box.
Can I have multiple .htaccess files?
Yes. You can place an .htaccess file in any directory within your web root. Apache processes them in order from the root to the requested directory. A child directory's .htaccess rules override the parent's for that path. However, using fewer .htaccess files is better for performance — each one requires a filesystem lookup on every request.
Will a bad .htaccess crash my site?
A syntax error in .htaccess will typically cause Apache to return a 500 Internal Server Error for every page on your site. Always keep a backup of your working .htaccess before making changes. If you get locked out, rename or delete the .htaccess file via FTP or your hosting file manager to restore access.
Related Tools
- Slug Generator — create URL-friendly slugs from any text.
- Robots.txt Generator — build a robots.txt file to control search engine crawling.