.htaccess Generator
Generate .htaccess rules for redirects, caching, security headers, and more.
# Force HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# Enable GZIP compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>
# Browser caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "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"
ExpiresByType text/html "access plus 1 hour"
</IfModule>
# Security headers
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set X-XSS-Protection "1; mode=block"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>About this tool
The .htaccess Generator is a tool for creating Apache web server configuration files that control redirects, caching, security headers, and more—all without needing root access to your server. Whether you're managing a small blog or a medium-sized website, .htaccess files allow you to override your server's main configuration at the directory level, giving you fine-grained control over how your site behaves.
This generator lets you quickly build custom .htaccess configurations by selecting the features you need: HTTPS enforcement, URL redirects (with or without www), GZIP compression, browser caching, security headers, hotlink protection, and custom error pages. The tool automatically generates the correct Apache directives for each option you choose, then displays the complete configuration that you can copy and paste directly into your .htaccess file.
Note that .htaccess only works on Apache servers; Nginx, IIS, and other modern platforms have different configuration methods. Also, .htaccess files are read on every request, so for high-traffic sites, placing configuration directly in the main server config is slightly faster. But for most small to medium websites, .htaccess is a convenient and practical solution for server-level customization.
Frequently Asked Questions
Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.