.htaccess Generator
Build an Apache .htaccess file: force HTTPS, add or remove www, 301 redirects, compression, caching, security headers, hidden file blocking and a custom 404.
How to make an .htaccess file
Pick the rules
Redirect HTTP to HTTPS, add or remove www, redirect old paths, compress text, or cache static files.
Add protection
Add security headers, block hidden files, or set a custom 404 page.
Check the result
The file updates as you type.
Save it
Copy it, or download it as .htaccess for the root of your site.
Test on a staging copy first, since a bad rule can take a site offline.
Worked example
This is what .htaccess Generator gives for its own sample values. Open the tool above and change anything to try your own.
- Domain
- example.com
- Redirect HTTP to HTTPS
- Yes
- www handling
- Leave as it is
- Compress text files
- Yes
- Cache images, CSS and JavaScript
- Yes
- Add security headers
- Yes
.htaccess
# Generated by Sarva Tools
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^old-page/?$ /new-page [L,R=301]
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json application/xml image/svg+xml
...About .htaccess Generator
Build an Apache .htaccess file with the usual settings: redirect HTTP to HTTPS, add or remove www, redirect old paths, compress text, cache static files, add security headers, block hidden files and set a custom 404 page.
FAQs
Where does it go?
In the root folder of your site, as a file named .htaccess.
Can it break my site?
A mistake can cause errors, so keep a copy of the old file and test before you rely on it.
Does it work on nginx?
No. Use nginx Config Generator.