About .htaccess Generator
Comprehensive Overview
The .htaccess Generator creates Apache web server configuration rules for common tasks without editing the main server config. Generate rules for HTTPS enforcement, www canonicalization, GZIP compression, browser caching, security headers, CORS, custom error pages, and hotlinking protection. Each rule includes comments explaining what it does.
Key Features
- HTTPS Redirect — Force all HTTP traffic to HTTPS with a 301 permanent redirect using mod_rewrite.
- WWW Canonicalization — Redirect www to non-www or vice versa to avoid duplicate content issues.
- GZIP Compression — Compress text-based assets (HTML, CSS, JS, JSON, XML, SVG, WOFF2) to reduce bandwidth by 60-80%.
- Browser Caching — Set cache expiration headers for images (1 year), CSS/JS (1 month), and fonts (1 year) using mod_expires.
- Security Headers — Add X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, and Permissions-Policy headers.
- CORS Headers — Enable cross-origin resource sharing for APIs and CDN-served assets.
- Custom 404 Page — Set a custom error page path using the ErrorDocument directive.
- Hotlink Protection — Block other websites from embedding your images directly, saving bandwidth.
How to Use
- Check the boxes for the rules you want to include.
- Fill in optional fields (custom 404 path, domain for hotlinking).
- Click Process to generate the .htaccess rules.
- Copy the output and paste it into your
.htaccessfile in your website root directory.
Important Notes
- Apache Only — .htaccess files work only with Apache web servers. For Nginx, use the equivalent directives in nginx.conf.
- mod_rewrite Required — HTTPS and WWW redirects require mod_rewrite to be enabled. Most shared hosting providers have it enabled by default.
- Test First — Always test new .htaccess rules on a staging environment before applying to production. A syntax error can cause 500 Internal Server Error.
- File Location — Place the .htaccess file in the root directory of your website. Rules apply to that directory and all subdirectories.