Skip to main content

htaccess Generator

Build Apache .htaccess configuration from a library of common directives.

Free & unlimited
Features
Force HTTPS — settings
Browser caching — settings
Default cache duration (days)
Custom rules
All processing happens in your browser. No data is sent to any server.

About this tool

  1. 1

    Choose rule type

    Select from redirects, rewrites, security headers, caching, or access control.

  2. 2

    Configure the rule

    Enter the source path, destination URL, redirect type (301/302), and any conditions.

  3. 3

    Preview the output

    Review the generated .htaccess directives with inline comments explaining each rule.

  4. 4

    Copy or download

    Copy the rules to your clipboard or download the complete .htaccess file.

  • Use 301 redirects for permanent URL changes and 302 for temporary ones - search engines treat them differently.
  • Always test .htaccess changes on a staging server first to avoid locking yourself out.
  • Order matters - RewriteRule directives are processed top to bottom, and the first match wins.
  • Add the [L] flag to stop processing further rules after a match.
  • Generates redirect rules (301, 302), URL rewrites, and canonical redirects
  • Security headers: X-Frame-Options, Content-Security-Policy, HSTS
  • Cache-Control and Expires directives for static asset caching
  • IP-based access control and password protection rules
  • HTTPS and www/non-www canonicalization rules
  • Set up 301 redirects after a site migration to preserve SEO rankings
  • Force HTTPS and redirect www to non-www (or vice versa)
  • Add security headers to harden an Apache-hosted website
  • Configure browser caching rules for images, CSS, and JavaScript files
Place it in your web root directory (usually public_html or www). Rules apply to that directory and all subdirectories.
You likely have a rule that matches its own destination. Add a RewriteCond to exclude the target URL from matching.
No. .htaccess is Apache-specific. Nginx uses its own configuration syntax in server block directives.

Related tools

View all

We use anonymous analytics to improve ToolChamp. No personal data is stored or sold. Privacy Policy