.htaccess Generator

Generate Apache rewrite, caching, and security rules. Stop writing boilerplate by hand.

Canonical format

Generated .htaccess

# Generated by CodeItBro .htaccess tool
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

# Enable gzip compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json image/svg+xml
</IfModule>

# Leverage browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 hour"
</IfModule>

Clean server rules in minutes

Whether you force HTTPS, normalize www, or add caching headers, this generator delivers ready-made .htaccess snippets with helpful documentation.

  • • Pick a canonical domain
  • • Enable gzip + browser caching
  • • Block image hotlinking

Server Control

Rewrite Toolkit

HTTPS enforcement

Canonical redirects

How It Works

The .htaccess Generator runs entirely in your browser using JavaScript. Unlike other tools that send your data to a server, we process everything locally on your device. This guarantees 100% privacy and blazing fast speed.

  • No server interaction – data never leaves your device
  • Instant results since there is no network latency
  • Works offline once the page is loaded
  • Free to use with no usage limits

How to Use

1

Enter domain preferences

Choose your canonical domain (www vs non-www) and whether to force HTTPS.

2

Toggle performance/security

Add caching headers, gzip compression, or block hotlinking in one click.

3

Copy .htaccess snippet

Paste into the root of your Apache project or merge with existing rules.

Frequently Asked Questions

Where does .htaccess live?
Place the file at the root of your Apache-hosted site, typically the same directory as index.php or index.html.
Do these rules work on Nginx?
No. Nginx uses a different configuration format. This tool is for Apache servers only.
Will redirects stack?
Rules are written to avoid infinite loops, but always test after deployment to confirm server-specific behavior.
Can I combine with existing .htaccess?
Yes. Merge carefully and keep RewriteEngine On only once at the top.
Do I need mod_deflate/mod_expires?
Compression and caching sections only work if those Apache modules are enabled on your server.

Related Tools

The .htaccess Generator is maintained by CodeItBro. We aim to provide the best free developer tools on the web. If you have feedback or suggestions, please visit our contact page.