Support
Dev Tools / Generate .htaccess Rules

Browse by category

All categories

Generate .htaccess Rules

Generate Apache.htaccess rules for redirects, rewrites, security headers, and caching. Open a tab, paste, done. Close it and it is gone.

1
Choose rules
Select the rules you need — redirects, HTTPS force, caching, security headers
2
Configure
Customize each rule with your specific URLs and settings
3
Copy code
Copy the generated .htaccess code for your server

.htaccess Builder

Redirects all HTTP requests to HTTPS via 301
Compresses HTML, CSS, JS, JSON, XML, and SVG responses

Generated .htaccess

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Security Headers
<IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>
# Browser Caching
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresDefault "access plus 2 days"
</IfModule>
# Gzip Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE text/plain
</IfModule>
# Disable Directory Listing
Options -Indexes
Generated39 lines

Frequently Asked Questions

Does it test the rules?

The generator validates syntax. Test on a staging server before deploying to production.

What Apache version is supported?

Rules are generated for Apache 2.4+ with mod_rewrite enabled.

Is it safe to paste production data?

Yes. The .htaccess output is built in JavaScript on this page and only ever exists in your browser tab. Production paths, secret URLs, and IP allowlists never leave your device.

This tool is free thanks to our sponsors. Support Loft Tools