.htaccess Generator
Generate Apache .htaccess configuration rules for redirects, CORS, caching, compression, security headers, and more.
About This Tool
The .htaccess Generator is a free browser-based tool that helps developers and system administrators create correctly formatted Apache .htaccess configuration files without memorizing the complex directive syntax. The .htaccess file is one of the most powerful configuration mechanisms available on Apache servers, used by millions of websites for URL management, security, and performance optimization.
Writing .htaccess rules by hand is error-prone and often frustrating. A misplaced directive, incorrect regex pattern, or missing RewriteEngine declaration can break your entire site or create redirect loops. This visual builder eliminates those problems by generating syntactically correct Apache directives every time. Choose from preset configurations for common use cases like basic security hardening, performance optimization, or a comprehensive full configuration that combines all features.
The tool supports a wide range of Apache features: HTTP to HTTPS and www canonicalization redirects, custom 301 and 302 redirects, CORS headers for API access, browser caching with mod_expires, gzip compression with mod_deflate, security headers like Content-Security-Policy and Strict-Transport-Security, IP-based access control, user agent blocking, custom error pages, and URL rewriting rules for clean URLs.
All processing happens entirely in your browser using JavaScript.
No data is sent to any server, and no account is required. The
generated .htaccess content can be copied to your clipboard or
downloaded as a ready-to-use .htaccess file that you
can drop directly into your website's root directory.
How to Use
- Optionally select a preset at the top to start with a common configuration: Basic (redirects + security), Performance (caching + compression), or Full (all features).
- Toggle individual sections on or off using the switches next to each section header. Only enabled sections are included in the output.
- Configure each section using the provided inputs. For example, in the Redirects section, enable HTTPS enforcement, www canonicalization, and add custom redirects.
- Review the generated .htaccess content in the output panel on the right side. The output updates in real time as you make changes.
- Click Copy to copy the generated content to your clipboard, or Download to save it as an
.htaccessfile. - Upload the file to your website's root directory. Make sure the file name starts with a dot (
.htaccess) and that your hosting provider supports Apache withmod_rewriteenabled.
FAQ
What is an .htaccess file?
An .htaccess (hypertext access) file is a directory-level configuration file for the Apache web server. It allows you to override server-wide settings on a per-directory basis without editing the main Apache configuration. Common uses include URL redirects, access control, caching rules, and security headers.
Where should I place the .htaccess file?
Place the .htaccess file in the root directory of your website (the same directory as your index.html or index.php). The rules apply to that directory and all subdirectories. You can also place additional .htaccess files in subdirectories to override parent-level rules.
Does .htaccess work with Nginx?
No. The .htaccess file is specific to the Apache web server. Nginx does not support .htaccess files. If you use Nginx, you need to add equivalent directives to your nginx.conf or server block configuration file. DevToolbox also offers an Nginx Config Generator for that purpose.
What is mod_rewrite and why does my .htaccess need it?
mod_rewrite is an Apache module that provides URL rewriting capabilities. It is required for URL redirects, removing file extensions from URLs, enforcing HTTPS, and many other common .htaccess rules. Most shared hosting providers have mod_rewrite enabled by default. The RewriteEngine On directive activates it.
Will .htaccess affect my website performance?
There is a small performance overhead because Apache reads .htaccess files on every request and walks up the directory tree checking for them. For high-traffic sites, it is better to move rules into the main server configuration (httpd.conf or apache2.conf) and disable .htaccess with AllowOverride None. For most sites, the overhead is negligible.
How do I enable gzip compression with .htaccess?
You can enable gzip compression using mod_deflate. The generated rules add AddOutputFilterByType DEFLATE directives for common MIME types like text/html, text/css, application/javascript, and application/json. This typically reduces file sizes by 60-80%, improving page load times significantly.
Is my data safe with this tool?
Yes. The entire tool runs client-side in your browser. No data is transmitted to any server. Your configuration details, domain names, and IP addresses never leave your machine. You can verify this by checking your browser's network tab.
Related Tools
Nginx Config Generator
Generate Nginx server blocks visually. Configure reverse proxy, SSL, static files, and redirects with a GUI.
Robots.txt Generator
Generate robots.txt files with a visual editor for user-agents, allow/disallow rules, and sitemap entries.
Meta Tag Generator
Generate HTML meta tags, Open Graph, and Twitter Card tags with live SNS preview.
Curl to Code Converter
Convert curl commands to Python, JavaScript fetch, PHP, Go, and more programming languages.