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
.htaccess preview
# Generated .htaccess — ToolChamp# Force HTTPSRewriteEngine OnRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]# Browser caching (30 days default)<IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 30 days" ExpiresByType text/css "access plus 1 year" ExpiresByType application/javascript "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year"</IfModule># Security headers<IfModule mod_headers.c> Header set X-Content-Type-Options "nosniff" Header set X-Frame-Options "SAMEORIGIN" Header set X-XSS-Protection "1; mode=block" Header set Referrer-Policy "strict-origin-when-cross-origin" Header set Permissions-Policy "camera=(), microphone=(), geolocation=()"</IfModule>All processing happens in your browser. No data is sent to any server.
About this tool
- 1
Choose rule type
Select from redirects, rewrites, security headers, caching, or access control.
- 2
Configure the rule
Enter the source path, destination URL, redirect type (301/302), and any conditions.
- 3
Preview the output
Review the generated .htaccess directives with inline comments explaining each rule.
- 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.