developer Tool
.htaccess Generator
Create custom Apache .htaccess files for HTTPS redirects, security rules, Gzip compression, and caching.
Apache .htaccess Generator
Generate secure Apache .htaccess configuration files for HTTPS redirects, security hardening, Gzip compression, and caching.
HTTPS & Domain Redirects
Security & Server Hardening
Performance & Error Documents
Generated .htaccess CodeApache Web Server
# ====================================================================
# .htaccess File Generated via UnitsAll
# https://unitsall.com/tools/developer/htaccess-generator
# ====================================================================
# Enable Rewrite Engine
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force HTTPS / SSL Redirect
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Security & Server Hardening
Options -Indexes
# Prevent access to .htaccess and .htpasswd
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
# Prevent access to hidden dot files (.git, .env, etc.)
<FilesMatch "^\.(git|env|config|bak)">
Require all denied
</FilesMatch>
# 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 Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
# Custom Error Pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
# Custom URL Redirects
Redirect 301 /old-page /new-page
# Gzip / Deflate Text Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json application/xml svg+xml
</IfModule>
# Leverage Browser Caching (Mod_Expires)
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
Custom 301 / 302 Redirect Rules
How .htaccess Generator Works
Generates Apache HTTP Server directives for URL rewriting, access control, and performance optimization.
Frequently Asked Questions
What is a .htaccess file used for?
A .htaccess file is a directory-level configuration file supported by Apache web servers to alter configuration.