.htaccess Generator
Build Apache .htaccess rules for redirects, security, compression, caching & more — no coding required
Redirects all HTTP traffic to HTTPS using mod_rewrite. Requires SSL certificate to be installed.
Enables mod_deflate to compress HTML, CSS, JS, XML, and JSON responses. Typically reduces transfer size by 60–80%.
Pick your Apache rules from the toggle panel — HTTPS redirects, GZIP compression, browser caching, security headers, IP blocking, hotlink protection — and get a clean .htaccess file with correct mod_rewrite syntax and proper flags. No copy-pasting mismatched Stack Overflow snippets that break each other.
And everything runs in your browser. Nothing gets uploaded.
How It Works
Flip on the sections you want from the left panel. Each toggle adds the matching Apache directives to the output on the right, with inline comments so you know what each block does. Tweak values like cache durations or blocked IPs if you need to. When it looks good, hit copy or download a ready-to-upload .htaccess file.
Examples
Force HTTPS + WWW Redirect
You just installed an SSL certificate and want all traffic on HTTPS with the www prefix.
Enable "Force HTTPS" toggle
Enable "WWW Redirect" toggle
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
GZIP Compression + Browser Caching
Your PageSpeed score is tanking because static assets aren't compressed or cached. Two toggles fix it.
Enable "GZIP Compression" toggle
Enable "Browser Caching" toggle
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
</IfModule>
Custom Error Pages + Security Headers
You want branded 404/403 pages instead of the ugly Apache defaults, plus headers that stop clickjacking and XSS.
Enable "Custom Error Pages"
Enable "Security Headers"
Set 404 → /errors/404.html
Set 403 → /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
Header set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options "nosniff"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "strict-origin-when-cross-origin"
Who Uses This
Setting up redirects, caching, and security headers on Apache-hosted projects without memorizing directive syntax.
Forcing HTTPS store-wide and adding hotlink protection so product images don't get scraped.
Creating 301 redirects for domain migrations and canonical URL enforcement without touching server config.
Learning Apache configuration by seeing how toggles map to actual .htaccess directives in real time.
Common Mistakes
Your rules do nothing because the file is in a subdirectory instead of the document root. Apache reads .htaccess from the directory it sits in, not globally. Make sure the file is in your site's root folder (usually public_html or www).
Two redirect rules that both match the same URL pattern create a redirect loop — your browser shows "too many redirects" and nothing loads. Use the [L] flag on the first rule that should win, or combine conditions so only one fires.
You paste in redirect rules and get a 500 Internal Server Error. The server doesn't have mod_rewrite turned on. Check with your host or add <IfModule mod_rewrite.c> wrappers so the file doesn't break when the module is missing.
Technical Details
- Processing: 100% client-side — nothing is sent to a server
- Output Format: Standard Apache 2.x .htaccess syntax
- Download: Plain text file named
.htaccess - Browser Support: Chrome, Firefox, Safari, Edge
- Dependencies: None — pure HTML, CSS, and JavaScript
Frequently Asked Questions
What is an .htaccess file and what does it do?
It's a plain text configuration file for Apache web servers. It sits in your site's root directory and controls things like URL redirects, access restrictions, caching rules, and error pages. Changes take effect immediately — no server restart needed.
Is the generated .htaccess code safe for production?
The output follows standard Apache 2.x syntax and uses widely recommended directives. That said, always test on staging first. Server setups vary — modules, permissions, and existing rules can all affect behavior. Verify it works before pushing live.
Does .htaccess work on Nginx or LiteSpeed?
Nginx ignores .htaccess entirely — it uses its own config files. LiteSpeed does support .htaccess for most common directives, though a few advanced Apache modules won't carry over. If you're on Nginx, you'll need to convert these rules to Nginx syntax manually.
Can .htaccess slow down my website?
Slightly, yes. Apache reads .htaccess on every request and checks every parent directory for one too. For most sites this is negligible. If you have hundreds of complex rules or deeply nested directories, moving the rules into the main server config (httpd.conf) is faster.
How do I upload an .htaccess file?
Use FTP, SFTP, or your hosting panel's file manager. Upload the file to your site's root directory (usually public_html). The filename starts with a dot, so some FTP clients hide it by default — turn on "show hidden files" if you can't see it after uploading.