</>
DevToolHub

.htaccess Generator

Build your .htaccess file visually — redirects, security rules, caching headers, and compression. Copy the output or download the file directly.

Redirects
Security
Caching & Performance
Custom Rules
Generated .htaccess
# .htaccess — Generated by DevToolHub
# https://devtoolhub.co/tools/htaccess-generator

# ==============================
# Security
# ==============================

# Disable directory browsing
Options -Indexes

# Block access to .env files
<FilesMatch "^\.env">
    Order allow,deny
    Deny from all
</FilesMatch>

# Block access to .git folder
RedirectMatch 404 /\.git

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 301 or Redirect 302 lines for each old-to-new URL pair you add.
  • Security — toggles produce directives like Options -Indexes, FilesMatch blocks for .env files, RedirectMatch 404 for .git, HTTPS enforcement via RewriteRule, and hotlink protection.
  • Caching — enables mod_expires with sensible defaults: 1 month for images and fonts, 1 week for CSS/JS, no cache for HTML.
  • Compression — uses mod_deflate to 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

DirectivePurposeExample
RedirectSends visitors from one URL to anotherRedirect 301 /old /new
RewriteRuleRewrites URLs using regex patternsRewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]
Options -IndexesDisables directory listingOptions -Indexes
ErrorDocumentCustom error pagesErrorDocument 404 /404.html
ExpiresByTypeSets caching duration by MIME typeExpiresByType image/jpeg "access plus 1 month"
AddOutputFilterByTypeEnables compression per content typeAddOutputFilterByType DEFLATE text/html
FilesMatchApplies rules to files matching a pattern<FilesMatch "\.env">
Header setAdds or modifies HTTP response headersHeader 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