Skip to content
JustTools

.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.

Runs in your browser Free · no sign-up

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. reaches https:// 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. 1

    Pick a starting point

    Choose Recommended basics, WordPress, Static site or SPA or PHP app — or start empty.

  2. 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. 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. 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. 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

OptionRuleEffect
Force HTTPSRewriteCond %{HTTPS} !=on then RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]http:// goes to https://, keeping the path and query
Remove wwwRewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]www.example.com goes to example.com
Moved pageRedirectMatch 301 ^/old-page/?$ /new-pagethat URL only, with or without a final slash
Moved folderRedirect 301 /blog /news/blog/post goes to /news/post
Removed pageRedirectMatch gone ^/old-page/?$“410 Gone”: the page was removed on purpose
Folder listings offOptions -Indexesa folder without an index page shows 403
Hide dot filesRedirectMatch 404 "/\.(?!well-known(?:/|$))".env and .git answer 404
Custom 404 pageErrorDocument 404 /404.htmlyour page, still with status 404
CachingExpiresByType text/css "access plus 1 month"returning visitors reuse the file
CompressionAddOutputFilterByType DEFLATE text/html …text is sent with gzip, or Brotli where available

Which redirect code to use

CodeMeaningUse it when
301Moved permanentlya page or site has a new address for good — search engines move its ranking to the new URL
302Found (temporary)the page will come back, such as during maintenance or a short campaign
307Temporary, method keptas 302, when forms that POST must keep working
308Permanent, method keptas 301, for APIs and forms that POST
410Gonethe 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?

In the top folder of your website — usually 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?

Browsers and operating systems hide or rename files whose names start with a dot. Upload htaccess.txt and rename it to .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?

Put your previous .htaccess back (or rename the new one) and the site returns at once. The usual causes are a module your host has disabled or a rule your host does not allow in .htaccess. Keep Skip rules whose module is missing on, then add the groups back one at a time to find the one your server rejects.

How do I redirect HTTP to HTTPS and www to non-www together?

Turn on Force HTTPS and choose Remove www. The rules are written in an order that sends http://www.example.com/page to https://example.com/page in a single redirect.

Is the password I type for .htpasswd safe?

Yes. It is hashed with bcrypt inside your browser and never leaves it; only the finished line is shown. It is not saved with your other choices either.

Does this work with WordPress?

Yes. Choose the WordPress preset: your rules are placed above the standard # BEGIN WordPress block, which WordPress keeps rewriting on its own. Anything above that block is left alone.

Will it work on Nginx or IIS?

No. .htaccess is read by Apache and LiteSpeed only. Nginx needs the same rules in its server configuration, and IIS uses web.config.

Are my settings stored anywhere?

Only in your browser’s local storage, so they are still there when you come back. Nothing is uploaded. Clearing the site data for JustTools removes them.

Keep going

Browse every tool

Last updated Report a problem or suggest a feature