How to use the .htaccess generator
An .htaccess file holds per-folder settings for the Apache web server (LiteSpeed reads it too). Nginx, Cloudflare Pages and Netlify ignore it, so this tool only helps on Apache hosting.
- Your domain: needed only for Add www and hotlink protection.
- Address rules: Force HTTPS, Behind Cloudflare, a CDN or a proxy (stops redirect loops), Remove trailing slash and Single-page app routing.
- www or no www: Leave as is, Remove www or Add www. Doing both would redirect forever, so it is one choice.
- Speed and protection: Gzip, Browser caching, Custom 404 and 500 pages, Block image hotlinking.
- 301 redirects: one per line, the old path, a space, then the new path or a full URL.
- Press Copy or Download .htaccess and put the file in your web root. Many browsers save it as htaccess.txt, so rename it to
.htaccess.
How the rules work
Rewrites use mod_rewrite, redirects use the Redirect directive, and compression and caching use mod_deflate and mod_expires. Each block sits in an IfModule check, so a module your host lacks is skipped. The www rule runs before the HTTPS rule, so visitors get one redirect. A Redirect line matches the old path and everything below it, so /blog/2020 catches /blog/2020/post but not /blog/2020x. The directives follow the Apache 2.4 documentation.
Worked example
The page opens with Force HTTPS, Gzip, Browser caching and two redirects ticked. The output is 39 lines and 1,522 bytes. The first two blocks:
# Generated by ClickSolveTools .htaccess Generator
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
<IfModule mod_alias.c>
# 301 redirects
Redirect 301 /old-page /new-page
Redirect 301 /blog/2020 /archive
</IfModule>
Then come one compression line for 20 file types and 14 caching lines: one year for images and fonts, one month for CSS and JavaScript, none for HTML. A request for http://example.com/page.html?x=1 gets a 301 to the https address with ?x=1 kept.
Limits and edge cases
- Apache ignores .htaccess unless AllowOverride permits it, and a directive that is not allowed gives a 500 error, so keep a backup.
- Single-page routing sends every unknown URL, missing images included, to index.html, so your 404 page rarely shows. The folder needs an index.html or the rule loops.
- Remove trailing slash loops on WordPress and other systems that add the slash back, so use it for static sites.
- Redirect cannot match a query string such as ?id=5. Hotlink protection relies on the Referer header, which can be faked.
- Pair redirects with a robots.txt file and a sitemap.
Frequently asked questions
How do I force HTTPS with .htaccess?
Tick Force HTTPS and copy the result into the .htaccess file in your web root. Every http request then gets a 301 redirect to the same address on https. Install your SSL certificate first, or visitors will see a certificate error.
Why is my .htaccess not working or causing a 500 error?
Check that the file is named .htaccess with the leading dot and sits in the right folder. Apache ignores it unless AllowOverride permits it, and a directive that is not allowed gives a 500 error. The Apache error log names the line.
How do I redirect www to non-www, or the other way round?
Pick Remove www or Add www. Remove www needs no domain. Add www uses the domain you type, so subdomains such as blog.example.com are left alone. Doing both would redirect forever, so it is a single choice.
Why do I get too many redirects after forcing HTTPS behind Cloudflare?
Behind Cloudflare, a CDN or a load balancer the server may see plain http even when the visitor used https, so the redirect repeats. Tick Behind Cloudflare, a CDN or a proxy and the rule skips the redirect when the X-Forwarded-Proto header says https.
Can I use .htaccess on Nginx or Cloudflare Pages?
No. Nginx, Cloudflare Pages and Netlify do not read .htaccess files and use their own configuration, such as an nginx.conf server block or a _redirects file. This generator is for Apache and LiteSpeed hosting.
Sources: Apache HTTP Server 2.4 .htaccess how-to, mod_rewrite and mod_alias, checked October 2026.