How to use it
- Switch on the features you need. The file updates as you type.
- Fix any line that the tool lists as invalid; those lines are left out of the output.
- Copy the result into a file named
.htaccessin your site root, or append it to the existing one. - Open your site and test every redirect with a private window, because browsers cache 301 redirects.
What each block writes
- HTTPS and www:
RewriteEngine OnwithRewriteCondandRewriteRule ... [L,R=301]. When you combine HTTPS with www, a single redirect goes straight to the final address instead of two hops. - Redirects: one
Redirect <code> <from> <to>line each (mod_alias). - Error pages:
ErrorDocument <code> <path>. - Directory listings:
Options -Indexes. - IP blocking:
Require all grantedandRequire not ip ...inside<RequireAll>, the Apache 2.4 syntax. - Compression:
AddOutputFilterByType DEFLATE ...for HTML, CSS, JavaScript, JSON, XML and SVG, inside<IfModule mod_deflate.c>. - Caching:
ExpiresByType <type> "access plus <time>"inside<IfModule mod_expires.c>. - Hotlink protection: a referrer check that returns 403 for image requests from other sites, while still allowing requests with an empty referrer.
Example
Choosing HTTPS and removing www writes a rule that sends http://www.example.com/page to https://example.com/page in one step, with the path and query string kept.
Tips
Start with a short cache time for CSS and JS unless file names change with each release, because a long cache hides updates from returning visitors. Back up the current .htaccess before replacing it.