.htaccess Generator
Generate Apache .htaccess configuration files for 301 redirects, SSL enforcement, browser caching, and directory security.
# Apache .htaccess configuration generated via BitSmith Tools
RewriteEngine On
RewriteBase /
# Force HTTPS Redirection
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect www to apex domain
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# Disable Directory Browsing
Options -Indexes
# Custom Error Document
ErrorDocument 404 /404.html
# Block Access to Hidden Files & Directories
<FilesMatch "^.(?!well-known)">
Require all denied
</FilesMatch>
# Enable Gzip Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</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/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
How to Use .htaccess Generator
- 1Step 1
Toggle your required server rules: HTTPS enforcement, WWW redirection, and security shields.
- 2Step 2
Enable browser caching and Deflate compression for improved Google PageSpeed scores.
- 3Step 3
Review the live compiled .htaccess block in the preview terminal.
- 4Step 4
Download or copy the .htaccess file into your server document root.
Technical Specification & Client Security
Directive definitions are tested against Apache HTTP Server 2.4+ specifications. Mod_rewrite, mod_deflate, and mod_expires directives are wrapped in safety blocks.
Input & Output Transformation Examples
RewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Frequently Asked Questions
Where should the .htaccess file be uploaded?
Upload the .htaccess file to the public_html or root web directory of your Apache or LiteSpeed web server.
Does this generator work with Nginx servers?
No. The .htaccess configuration format is specific to Apache and LiteSpeed web servers. Nginx requires configuration in its nginx.conf server blocks.
Will these rules break SSL certificates or Let’s Encrypt renewal?
The hidden file block specifically allows the .well-known directory so ACME automated SSL certificate issuance continues to succeed without interruption.