.htaccess Generator
Build Apache .htaccess rules for redirects, HTTPS enforcement, cache control, hotlink protection and custom error pages. Copy-ready output. Free, browser-based.
Enable the sections you need, configure the options, then click Generate.
Redirects every HTTP request to the secure HTTPS equivalent using a 301 permanent redirect.
Prevents Apache from showing a list of files when no index file is present in a directory.
What Is .htaccess?
An .htaccess file is a per-directory configuration file for the Apache web server. It overrides the main server config for requests within that directory tree, allowing you to set up redirects, authentication, caching headers and security rules without restarting the server.
Common Use Cases
| Rule | Purpose |
|---|---|
| Force HTTPS | Redirect all HTTP traffic to secure HTTPS |
| WWW redirect | Canonicalise domain to www or non-www |
| Browser caching | Tell browsers to cache CSS/JS/images locally |
| Hotlink protection | Block other sites from embedding your images |
| Custom error pages | Show branded 404/403/500 pages |
| Disable directory listing | Prevent visitors from browsing your file tree |
Important Notes
Apache must have AllowOverride All set in its virtual host config for .htaccess files to take effect. Also ensure mod_rewrite is enabled (a2enmod rewrite on Debian/Ubuntu). Always back up your existing .htaccess before overwriting it.