Custom Web Audits
Run Audit Demo Audit Audit Types Free Tools Pricing What We Analyze 🔒 Login
← All free tools
⚙️

.htaccess Generator

Generate a recommended Apache .htaccess for your domain — force HTTPS, canonicalize www, enable gzip and browser caching, and add baseline security headers. Download and drop it on your server.

⚡ Interactive demo — sample data
Generated a recommended Apache .htaccess with HTTPS, host canonicalization, compression, caching and security headers. Back up your existing file before replacing it.
Force HTTPS: 301 redirect from http to https Looks good
Canonical host: www → non-www 301 (flip the rule if you prefer www) Looks good
Compression + caching: gzip/DEFLATE plus mod_expires browser cache headers Looks good
Security headers: X-Content-Type-Options, X-Frame-Options, Referrer-Policy Looks good
Apache only — this file has no effect on Nginx servers Warning

About this tool

Generate a recommended Apache .htaccess for your domain — force HTTPS, canonicalize www, enable gzip and browser caching, and add baseline security headers. Download and drop it on your server.

How it works

Enter your domain
Type your domain (example.com). We use it to build the canonical host rules so the generated file redirects www to non-www for your exact domain — no placeholder editing needed for the host part.
Review the generated .htaccess
You get a complete, commented Apache .htaccess that forces HTTPS, canonicalizes the host, enables gzip compression and browser caching, and adds baseline security headers. Each block is labeled so you understand what it does.
Download and add it to your server
Download the file (or copy the contents), back up any existing .htaccess first, then upload it to your site's root directory. Reload your site to confirm HTTPS and the www/non-www redirect work as expected.

What we check

Common issues we catch

Where this matters

Frequently asked questions

What is an .htaccess file?
It's a per-directory configuration file that Apache reads to apply rules like redirects, compression, caching and headers without touching the main server config. Placed in your site root, it affects your whole site. Only Apache and Apache-compatible servers like LiteSpeed use it.
Does this work on Nginx?
No. Nginx ignores .htaccess entirely — its equivalent rules live in the server block configuration, which usually requires host-level access. This generator produces Apache syntax, so confirm your hosting runs Apache or LiteSpeed before using it.
Where do I put the file?
Upload it to your website's root directory (often public_html or www) so it applies to the whole site. Make sure it's named exactly .htaccess with the leading dot and no extension, or Apache won't recognize it.
Should I redirect to www or non-www?
Either is fine for SEO — what matters is picking one and being consistent. The default here redirects www to non-www. If your backlinks, Search Console property and existing setup use www, flip the rule so you redirect toward www instead.
Will this break my existing redirects?
It can, if you replace an .htaccess that already has rules. Always download a backup of your current file first, and merge these blocks in rather than overwriting — especially on WordPress, where the permalink block must stay intact.
Why am I getting a redirect loop after adding it?
The most common cause is a CDN or proxy that terminates HTTPS upstream, so Apache sees the request as http and keeps redirecting. In that setup the HTTPS condition needs to check a forwarded header like X-Forwarded-Proto instead of %{HTTPS}. Adjust the condition for your stack.
Do compression and caching really help speed?
Yes. Gzip/DEFLATE shrinks text assets (HTML, CSS, JS) significantly over the wire, and browser caching means returning visitors re-download far less. Both are low-effort wins that improve real-world load time and Core Web Vitals.
Is it safe to add the security headers?
The included headers — nosniff, SAMEORIGIN frame options and a Referrer-Policy — are conservative and safe for most sites. SAMEORIGIN could block legitimate embedding of your pages in third-party iframes, so if you intentionally allow that, loosen X-Frame-Options accordingly.

This is one of several free SEO tools from Custom Web Audits. For a complete, prioritized analysis of your whole website, run a full audit.