.htaccess Generator
Switch on what your site needs — HTTPS, redirects, security headers, password protection, compression, caching — and get a commented .htaccess file for Apache 2.4 that warns you about mistakes before you upload it.
At a glance
- Builds an .htaccess file for Apache 2.4 from switches and short forms: HTTPS, www, redirects, error pages, security, passwords, compression, caching and URL rewriting.
- Every kind of rule was loaded into a real Apache 2.4 server and checked with requests while the tool was built.
- Rules that need an optional module are wrapped in
<IfModule>, so a server without it skips them instead of showing “500 Internal Server Error”. - Redirects can be 301, 302, 307, 308 or 410, for one URL, a whole folder or a regular expression — or pasted as a list. Loops, missing targets and duplicates are flagged.
- The HTTPS and www rules are ordered so that
http://www.reacheshttps://without www in one redirect, with an option for sites behind Cloudflare or a load balancer. - Includes an .htpasswd line maker: the password is hashed with bcrypt in your browser, in the
$2y$form Apache expects. - Presets for a typical site, WordPress, a static site or single-page app, and a PHP app.
- Runs in your browser. Your domain, redirects and passwords are not uploaded; your choices are saved on your device only.
Step by step
How to create an .htaccess file
- 1
Pick a starting point
Choose Recommended basics, WordPress, Static site or SPA or PHP app — or start empty.
- 2
Switch on what you need
Open each group — HTTPS and www, redirects, security, speed — and turn rules on. Read any warning that appears above the file.
- 3
Download the file
Click Download (or Copy). The file is saved as htaccess.txt because computers hide files that start with a dot.
- 4
Upload and rename
Keep a copy of your current .htaccess, upload the new file to the top folder of the site (often public_html) and rename it to .htaccess.
- 5
Test straight away
Open the site, an old URL you redirected and a page that does not exist. If you see “500 Internal Server Error”, put the old file back.
Features
Everything you need, nothing you don’t
Explained, not just generated
Each section of the file starts with a comment saying what it does, so you can read it again in a year. Switch the comments off for a compact file.
Catches mistakes first
A redirect to itself, a relative .htpasswd path, an invalid IP address, HSTS without HTTPS — each is pointed out before the file reaches your server.
Safe by default
Module checks keep a missing module from taking the site down, and hidden files such as .env and .git are closed while /.well-known/ stays open for certificates.
Redirects in bulk
Paste old and new paths from a spreadsheet, one pair per line. A line with only an old path becomes “410 Gone”.
Password protection with the hash
Get both halves: the rules for .htaccess and the bcrypt line for .htpasswd, for a whole folder or a single file.
Private
Nothing is sent to a server: the file is written, and the password hashed, in your browser.
What each option writes
| Option | Rule | Effect |
|---|---|---|
| Force HTTPS | RewriteCond %{HTTPS} !=on then RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | http:// goes to https://, keeping the path and query |
| Remove www | RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] | www.example.com goes to example.com |
| Moved page | RedirectMatch 301 ^/old-page/?$ /new-page | that URL only, with or without a final slash |
| Moved folder | Redirect 301 /blog /news | /blog/post goes to /news/post |
| Removed page | RedirectMatch gone ^/old-page/?$ | “410 Gone”: the page was removed on purpose |
| Folder listings off | Options -Indexes | a folder without an index page shows 403 |
| Hide dot files | RedirectMatch 404 "/\.(?!well-known(?:/|$))" | .env and .git answer 404 |
| Custom 404 page | ErrorDocument 404 /404.html | your page, still with status 404 |
| Caching | ExpiresByType text/css "access plus 1 month" | returning visitors reuse the file |
| Compression | AddOutputFilterByType DEFLATE text/html … | text is sent with gzip, or Brotli where available |
Which redirect code to use
| Code | Meaning | Use it when |
|---|---|---|
| 301 | Moved permanently | a page or site has a new address for good — search engines move its ranking to the new URL |
| 302 | Found (temporary) | the page will come back, such as during maintenance or a short campaign |
| 307 | Temporary, method kept | as 302, when forms that POST must keep working |
| 308 | Permanent, method kept | as 301, for APIs and forms that POST |
| 410 | Gone | the page was removed on purpose and has no replacement |
Before you upload
- .htaccess works on Apache and LiteSpeed. Nginx ignores it — check with your host if you are unsure which server you have.
- The file belongs in the site’s top folder. Rules apply to that folder and everything under it.
- The rewrite rules assume the site is at the root of the domain, not in a subfolder such as example.com/shop/.
- One mistyped line anywhere in the file causes “500 Internal Server Error” on every page. Keep the old file so you can restore it in seconds.
- Behind Cloudflare’s “Flexible” SSL or a load balancer, switch on Behind Cloudflare or a load balancer. Without it, Force HTTPS redirects for ever.
- Browsers remember 301 redirects and HSTS for a long time. Test with 302 first if you are unsure, and leave HSTS off until HTTPS works on every page.
- For PHP that does not run as an Apache module (PHP-FPM, most shared hosts today), the PHP limits are skipped; put them in a .user.ini file instead.
FAQ
Frequently asked questions
Where do I put the .htaccess file?
public_html, htdocs or www. The file must be named exactly .htaccess, with the dot and no extension. File managers often hide it; turn on “show hidden files”.Why is the download called htaccess.txt?
.htaccess on the server, or use Copy and paste into your host’s file editor.My site shows “500 Internal Server Error” after uploading. What now?
How do I redirect HTTP to HTTPS and www to non-www together?
http://www.example.com/page to https://example.com/page in a single redirect.Is the password I type for .htpasswd safe?
Does this work with WordPress?
# BEGIN WordPress block, which WordPress keeps rewriting on its own. Anything above that block is left alone.Will it work on Nginx or IIS?
Are my settings stored anywhere?
Keep going
Related tools
Robots.txt Generator
Create a robots.txt file free: block admin pages, AI training bots like GPTBot or SEO crawlers, add your sitemap, then test any URL against Google’s rules.
Sitemap Generator
Free XML sitemap generator: crawl your site or paste URLs, skip noindex, redirected and robots.txt-blocked pages, add lastmod and images, ready for Google.
Bcrypt Generator & Checker
Generate bcrypt hashes with cost 4–16 and $2a/$2b/$2y prefixes, or check a password against a bcrypt hash. Explains each part. Runs in your browser only.
Website SEO Checker
Free website SEO checker: audit any page’s title, meta description, headings, canonical, robots.txt, schema, Open Graph and AI crawler access, with fixes.
JSON Formatter & Validator
Format, validate, minify and repair JSON online. Get the exact line and column of every error, a collapsible tree view and sorted keys — private, in-browser.
XML to JSON Converter
Convert XML to JSON and JSON to XML online. Keeps attributes, arrays and leading zeros intact, shows exact error lines and never uploads your data.
Last updated Report a problem or suggest a feature