.htaccess Generator

Developer

Generate Apache .htaccess configuration files for URL rewriting, redirects, security headers, caching, compression, and more.

Quick Presets

URL Rewriting

Security

Performance

Custom Error Pages

.htaccess

# Generated by gentools.io - .htaccess Generator <IfModule mod_rewrite.c> RewriteEngine On # Force HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Remove www RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [L,R=301] # Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] </IfModule> # Security Headers <IfModule mod_headers.c> Header always set X-Frame-Options "DENY" Header always set X-Content-Type-Options "nosniff" Header always set X-XSS-Protection "1; mode=block" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" </IfModule> # Block access to hidden files and directories <FilesMatch "^\."> Require all denied </FilesMatch> # Disable directory listing Options -Indexes # Gzip Compression <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css AddOutputFilterByType DEFLATE text/javascript application/javascript application/json AddOutputFilterByType DEFLATE application/xml application/xhtml+xml AddOutputFilterByType DEFLATE image/svg+xml font/woff2 </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 text/javascript "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType font/woff2 "access plus 1 year" ExpiresByType font/woff "access plus 1 year" ExpiresDefault "access plus 2 days" </IfModule> # Disable ETags <IfModule mod_headers.c> Header unset ETag </IfModule> FileETag None

About .htaccess

The .htaccess file is an Apache web server configuration file that allows per-directory configuration including URL rewriting, authentication, and caching.

  • URL Rewriting - Redirect URLs, force HTTPS, remove trailing slashes
  • Security Headers - Add X-Frame-Options, HSTS, and other security headers
  • Performance - Enable compression, browser caching, and Keep-Alive
  • Error Pages - Configure custom 404 and 500 error pages

Important

The .htaccess file works with Apache web servers only. For Nginx, use the server block configuration instead. Always test your .htaccess changes on a staging environment first.

What is This Tool?

An .htaccess generator creates Apache configuration directives for URL rewriting, redirects, security headers, caching, and access control. Build .htaccess files visually without memorizing RewriteRule syntax or mod_headers directives.

.htaccess files provide per-directory Apache configuration without editing httpd.conf. Common uses include URL rewriting (mod_rewrite), redirects (301/302), MIME types, cache headers, CORS, and IP-based access control. Changes take effect immediately without restarting Apache.

Common Use Cases

URL Rewriting

Create clean URL rewrites for CMS platforms, SPA routing fallbacks, and SEO-friendly URL structures.

Redirect Management

Configure 301 permanent and 302 temporary redirects for domain migration, URL restructuring, and trailing slash handling.

Security Hardening

Add security headers (X-Frame-Options, CSP, HSTS), disable directory listing, and block IP ranges.

Performance

Configure browser caching, gzip/brotli compression, and ETag handling for faster page loads.

Frequently Asked Questions

Does .htaccess work with Nginx?

No. .htaccess is Apache-specific. Nginx uses nginx.conf directives. Use the Nginx config generator for Nginx servers.

Are RewriteRules complex?

Yes, regex-based rewrite rules can be tricky. This generator builds them visually so you don't need to write regex manually.

Does .htaccess affect performance?

Yes. Apache checks .htaccess in every directory on each request. For high-traffic sites, move rules to httpd.conf where possible.