Apache .htaccess Generator
Generates Apache .htaccess directives for common web server tasks. Copy the output into your .htaccess file at the web root or in a specific directory.
Common configurations
- Redirects: 301 (permanent) and 302 (temporary) redirects for URLs that have moved
- HTTPS enforcement: redirect all HTTP traffic to HTTPS
- www/non-www normalization: canonicalize to www or non-www consistently
- Caching rules: set Expires headers for static assets to improve performance
- Compression: enable mod_deflate for gzip compression
- Custom error pages: serve custom 404, 403, and 500 pages
- Directory listing: prevent Apache from listing directory contents
- Password protection: protect directories with HTTP Basic Auth
Important notes
.htaccessrequiresAllowOverrideto be enabled in the server's Apache config- Every request incurs a performance cost for .htaccess lookups, for high-traffic sites, apply rules in the main server config
- Test thoroughly after changes, a syntax error in .htaccess can return a 500 error for all requests
- Back up your existing .htaccess before adding new directives