.htaccess Generator
Generate Apache .htaccess rules for HTTPS enforcement, www redirects, Gzip compression, browser caching, hotlink protection, and custom error pages.
Custom Redirects
No custom redirects. Click Add to create one.
.htaccess Output
4 rules selected# Generated by ToolVerse .htaccess Generator
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Enable Gzip Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE text/javascript application/javascript application/json
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml
AddOutputFilterByType DEFLATE font/otf font/ttf image/svg+xml
</IfModule>
# Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/html "access plus 1 hour"
</IfModule>
# Disable Directory Listing
Options -IndexesDeployment Tips
- Upload .htaccess to your Apache server root directory
- Test redirects after deployment — check for redirect loops
- Force HTTPS before force-www (order matters!)
- Always back up your existing .htaccess before replacing
- 301 redirects are permanent (pass link equity), 302 are temporary
- Gzip and caching can significantly improve PageSpeed scores
Server Compatibility
Apache 2.x
✅ Full support
LiteSpeed
✅ Full support
Nginx
❌ Use nginx.conf
IIS
❌ Use web.config
Simple workflow
How to generate an .htaccess file
Step 1
Select the rules you need
HTTPS, www, Gzip, and caching cover most sites. Avoid enabling both force-www and remove-www.
Step 2
Add custom redirects
Map old paths to new URLs with 301 for permanent moves so link equity can pass.
Step 3
Backup, then upload
Save the current .htaccess first. Upload to the Apache site root and test for redirect loops.
Frequently asked questions
Does .htaccess work on Nginx?
No. This file is for Apache and LiteSpeed. Nginx uses server blocks in nginx.conf.
What is the difference between 301 and 302?
301 is permanent and typically passes ranking signals. 302 is temporary and should not be used for a lasting URL change.
Can .htaccess break my site?
Yes — a redirect loop or a bad rewrite can take pages down. Always keep a backup and test one change at a time.
Should HTTPS come before www rules?
Yes. Force HTTPS first, then canonicalize www vs non-www, so users hit one clean URL.