.htaccess Generator
Generate HTTPS and www redirects, 301 redirects, compression and browser caching rules, ready to paste.
The rules are generated in your browser; nothing you enter is sent anywhere.
What does an .htaccess file do?
.htaccess is a per-folder configuration file that the Apache web server reads. It goes in the site's root folder (usually public_html) and applies on every request without restarting the server. Redirects, compression, cache lifetimes and access restrictions are defined here. LiteSpeed servers read the same file; nginx does not use .htaccess, so the equivalent rules go in the server block.
HTTPS and www redirects
A site can open from four addresses: http://, https://, with www and without it. Search engines may treat these as separate pages; a permanent 301 redirect to a single address keeps rankings in one place. The simplest htaccess HTTPS redirect looks like this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
The tool combines the HTTPS and www choice into a single rule, so a visitor arriving at http://example.com reaches the final address with one redirect instead of two. If you use Cloudflare, set the SSL mode to Full or Full (strict); in Flexible mode the server always sees plain http and the redirect loops forever.
How to write a 301 redirect
For a page that moved or was renamed, add a permanent redirect from the old path to the new address:
RewriteRule ^old-page/?$ /new-page [R=301,L]
The left part is the path after the site root, without a leading slash; the right part is the new path or a full URL. The tool escapes special characters such as dots, matches the path with or without a trailing slash and adds a separate condition for old addresses with a query such as ?id=5. After setting up redirects, scan the page for old links with the broken link checker.
Before you upload the file
Back up your current .htaccess file. If software such as WordPress has its own rules, keep them and add the generated rules above the # BEGIN WordPress line. If the site shows a 500 error after uploading, the server does not allow one of the directives (most often Options); remove the last block you added and try again. Verify redirects with the website down checker and compression with the gzip and Brotli test.
More free tools
FAQ
About .htaccess Generator
In the site's root folder, where the index file lives (usually public_html or /var/www/html). The file name must be exactly .htaccess; if your browser saved it as htaccess.txt or _htaccess, rename it after uploading. Because the name starts with a dot, you may need to turn on show hidden files in your file manager.
The most common cause is a proxy in front of the server that terminates HTTPS: Cloudflare Flexible SSL or a load balancer. The server sees every request as http and keeps redirecting to https. Set the Cloudflare SSL mode to Full or tick the proxy option in the tool. Also check that the site address in WordPress settings matches your www choice.
Only after the site and all its pages open over HTTPS without problems and the SSL certificate renews automatically. HSTS tells browsers to open the site only over HTTPS for a year; if the certificate breaks, visitors cannot get in at all and removing the rule does not take effect right away. Verify the certificate with the SSL checker.