.htaccess Generator
Generate Apache .htaccess rules for HTTPS redirects, caching, GZIP, and security
Configuration Options
Force HTTPS
Redirect all HTTP traffic to HTTPS using mod_rewrite
Force www
Redirect non-www requests to www subdomain
Redirect URL
Enable GZIP Compression
Compress HTML, CSS, JS, and other text responses with mod_deflate
Browser Caching
Set cache expiry for images (1 month) and CSS/JS (1 week)
Block File Types
Comma-separated extensions to deny access to (e.g. log, bak, sql)
Custom 404 Page
Protect .htaccess
Deny direct HTTP access to the .htaccess file itself
.htaccess Output
# Force HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Enable 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 text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>
# Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/webp "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/html "access plus 1 hour"
</IfModule>
# Custom 404 Page
ErrorDocument 404 /404.html
# Protect .htaccess
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>Continue Exploring
Other Developer Tools you might like...
JSON Formatter
Format, validate, and minify JSON data with syntax highlighting
Base64 Encoder/Decoder
Encode text to Base64 and decode Base64 strings
URL Encoder/Decoder
Encode and decode URL components and query strings
UUID Generator
Generate random UUID v4 identifiers
Hash Generator
Generate MD5, SHA-1, SHA-256, and SHA-512 hashes from text
Regex Tester
Test and debug regular expressions with match highlighting
JWT Decoder
Decode and inspect JWT token header and payload
HTML Formatter
Beautify and format HTML code with proper indentation