.htaccess Generator

Web & Network

Generate Apache .htaccess configuration files for 301 redirects, SSL enforcement, browser caching, and directory security.

Rewrite & Canonical Rules
WWW Redirection
Security & Performance Optimizations
Compiled .htaccess
# 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

  1. 1Step 1

    Toggle your required server rules: HTTPS enforcement, WWW redirection, and security shields.

  2. 2Step 2

    Enable browser caching and Deflate compression for improved Google PageSpeed scores.

  3. 3Step 3

    Review the live compiled .htaccess block in the preview terminal.

  4. 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.

›Force HTTPS and apex domain canonicalization using 301 permanent rewrites
›Directory listing protection via Options -Indexes directive
›Sensitive hidden files and .git folder denial blocks
›Asset caching headers with mod_expires for images, CSS, and JavaScript
›Gzip and Deflate output compression configuration for reduced latency
›100% private in-browser generation with 1-click download

Input & Output Transformation Examples

Force HTTPS Redirection
Input:
RewriteCond %{HTTPS} off
Output:
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirect WWW to Apex Non-WWW
Input:
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
Output:
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.

Related Developer Utilities