Build a clean .htaccess file for Apache and LiteSpeed in minutes. Force HTTPS, fix www, redirect old pages, add caching and security headers, then copy the code. No coding needed.
The .htaccess file tells your server how to handle requests before your page loads. One wrong character can take your whole site offline with a 500 error, so writing these rules by hand is risky. The generator uses tested rule patterns and puts them in the right order, so redirects run first and nothing clashes.
# BEGIN WordPress block. The generator adds it for you when you pick the WordPress preset.| Rule | What it does | When to use it |
|---|---|---|
| Force HTTPS | Sends every http:// visit to https:// with a 301 redirect | Always, once your SSL certificate works |
| www or non-www | Picks one version of your domain so Google sees one site | Always. Pick one and keep it. |
| Trailing slash | Adds or removes the slash at the end of URLs | When pages load with and without the slash |
| Page redirects | 301 redirect from an old URL to a new one | After you move, rename or delete a page |
| Move site | Sends every URL to the same path on a new domain | When you change domain names |
| Caching and gzip | Tells browsers to keep files and makes files smaller | To speed up repeat visits |
| Security headers and HSTS | Adds browser safety headers and keeps visitors on HTTPS | When your whole site works on HTTPS |
| Hotlink protection | Stops other sites from showing your images | When others steal your bandwidth |
| Block bots and IPs | Returns 403 Forbidden to bad bots or addresses | When spam or scrapers hit your site |
Each switch maps to a tested rule group, based on the Apache documentation.
In your browserDomains, paths and redirect lines are cleaned. Lines that cannot work are skipped and you are told why.
In your browserRedirects come first, then HTTPS and www in one hop, then speed, security and WordPress rules.
In your browserFor example HSTS without an HTTPS redirect, or hotlink protection without your domain.
In your browserEach group is wrapped in comments and IfModule checks, so missing server modules do not break the site.
In your browserOne-hop HTTPS and www: the generator joins both checks so a visitor to http://example.com lands on https://www.example.com in a single 301 redirect, not two. Fewer hops means faster pages and cleaner signals for Google.
Redirect format: RewriteRule ^old-page/?$ /new-page/ [R=301,L]. R=301 means “moved for good” and L stops other rules from running after it.
Proxy and Cloudflare: if your site sits behind a proxy, the HTTPS check uses the X-Forwarded-Proto header so you do not get a redirect loop.
<IfModule mod_rewrite.c>
RewriteEngine On
# HTTPS and www in one redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>The output is exact: it is the code for the options you chose. What can differ is your server. Some hosts turn off modules like mod_headers, and some use Nginx, which ignores .htaccess. That is why you should always test after upload.
Force HTTPS and pick www or non-www in a single 301 redirect.
Paste many old and new URLs at once, or move a whole domain.
Browser caching and gzip compression for faster pages.
Security headers, HSTS, hotlink protection and bot blocking.
Keeps the WordPress block and can block xmlrpc.php.
Flags settings that could cause loops or broken images.
Force HTTPS, fix www and speed up your site without a plugin.
Set up clean 301 redirects after a redesign or site move.
Get a tested starting file and save time on every project.
Fix "not secure" warnings and duplicate site versions on your own.
First release with HTTPS, www, slash, redirects, caching, gzip, security headers, hotlink, bot and IP blocking, and 4 presets.
We run the tool against our test cases again and check the Apache documentation and Google redirect guidance for changes.
Tool page last reviewed on .
Tell us what you entered, what happened and what you expected. Our developer checks every report, fixes confirmed bugs as a high priority and tests the fix before it goes live.
This page follows our Editorial Policy and Methodology. If something here is wrong, our Corrections Policy explains how we fix it. Learn more about the SpellMistake team.
Based on 1 real user rating
How useful was the .htaccess Generator for you?
Ratings come from real visitors. One rating per person. We never add, edit or remove ratings.
An .htaccess file is a small settings file for Apache and LiteSpeed servers. It controls redirects, HTTPS, caching, security and more for the folder it sits in and every folder below it.
It is in the root folder of your website, often called public_html or www. Files that start with a dot are hidden, so turn on "show hidden files" in your file manager or FTP app.
Yes. It is 100% free, with no sign-up and no limits. Everything runs in your browser.
Turn on Force HTTPS in the generator, enter your domain and copy the code. It adds a 301 redirect that sends every http:// request to https://. Make sure your SSL certificate works first.
Add the old path and the new path as one line in the redirects box. The generator writes a 301 rule, which tells Google the page has moved for good and passes its value to the new URL.
A 500 error usually means a rule your server does not support or a typing mistake. Put your backup file back, then add rules one group at a time to find the cause.
No. Nginx does not read .htaccess files. Nginx rules go in the server config instead, so ask your host to add them for you.