ToolboxHub

⚙️.htaccess Generator

Generate Apache .htaccess rules for redirects, security, and caching.

Share:

WWW Preference

Generated .htaccess

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

# 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 image/svg+xml
</IfModule>

# Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/svg+xml "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"
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType application/json "access plus 0 seconds"
</IfModule>

# Security Headers
<IfModule mod_headers.c>
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-XSS-Protection "1; mode=block"
</IfModule>

# Block Directory Listing
Options -Indexes

About .htaccess Generator

.htaccess Generator creates valid Apache configuration snippets for the most common web server tasks — URL redirects, HTTPS enforcement, security headers, browser caching rules, gzip compression, and access control — through a guided interface, without needing to write Apache directives from scratch.

How to Use .htaccess Generator

  1. 1

    Select the rules you need

    Check the options for the Apache directives you want to generate — such as HTTPS redirect, www to non-www, cache headers, or security headers.

  2. 2

    Configure each rule

    Fill in any required values such as redirect source and destination URLs, cache durations, or allowed IP addresses.

  3. 3

    Copy and upload your .htaccess

    Copy the generated configuration and paste it into your existing .htaccess file or create a new one in your site's root directory.

Common Use Cases

  • Forcing HTTPS on all pages of a website by redirecting HTTP requests
  • Setting browser cache expiry headers to improve page load speed
  • Blocking specific IP addresses or requiring HTTP authentication on a directory
  • Setting up clean URL rewrites to remove file extensions like .php or .html

Frequently Asked Questions

What is an .htaccess file?
An .htaccess file is a directory-level Apache configuration file that controls URL rewriting, access control, MIME types, caching, compression, and security headers for the directory it resides in and its subdirectories.
Where do I place the .htaccess file?
The .htaccess file goes in the root directory of your website (the public_html or www folder). Rules apply to all files and subdirectories within that folder.
Will this work on Nginx servers?
No — .htaccess is specific to Apache web servers. Nginx uses a different configuration syntax. If your host uses Nginx, use a server block configuration instead.

Related Tools