.htaccess Generator

Use this .htaccess generator to build the Apache rules almost every site needs — force HTTPS, settle www versus non-www, redirect moved pages, and set custom error pages — each block explained in plain comments.

1Tick the rules your site needs
2Add your redirect pairs and error pages
3Copy or download the file — and back up your old one

Private by design: 100% in your browser — nothing is uploaded, no sign-up. This tool runs entirely on your device.

How to use this .htaccess generator

Tick only the rules your site actually needs — an .htaccess file should be short enough to read at a glance. Force HTTPS is right for almost every modern site, provided your SSL certificate is installed and covers the version of the domain you are forcing. Choose the www question once, deliberately, and let the redirect keep every visitor and search engine on that single version forever. Add redirect pairs for any page whose address has changed, one per line, old path first. Then copy the generated file — but before you replace anything on the server, download your current .htaccess as a backup. The new file takes effect the instant it is saved; the backup is what makes that fact relaxing instead of frightening.

Every block in the output carries a comment saying what it does. Keep those comments when you paste the file live: six months from now, the person reading your .htaccess at midnight during an outage is you, and the comments are the difference between understanding the file and fearing it.

Example output

With the default values on this page — force HTTPS, no www forcing, directory listings off, one index page, two redirects, a custom 404 and gzip on — the generator produces a file whose opening blocks look like this:

# Force one canonical address RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Turn off directory listings Options -Indexes # Custom 301 redirects (old page -> new page) Redirect 301 /old-services.html https://yourwebsite.com/services/ Redirect 301 /blog-old/ https://yourwebsite.com/blog/

That HTTPS block was verified with this tool's own code: with the HTTPS option on, the output always contains the RewriteCond %{HTTPS} off condition followed by the 301 rule — the standard, correct pairing. Redirects for moved pages appear in the same order you typed them.

Reading the rewrite rules

The HTTPS block is the one people fear most, so here it is in plain words. RewriteEngine On wakes the rewriting module. RewriteCond %{HTTPS} off sets the condition: "only when the visitor arrived over plain HTTP". RewriteRule then sends that visitor to the same host and the same page address, but over https, with R=301 marking the move permanent and L saying "stop processing further rules". The www rules work identically, matching the host name instead of the protocol. Once you can read one block, you can read them all — conditions first, then the action, then the flags in brackets.

A safe way to go live

Work in this order and .htaccess will never bite you. One: back up the existing file. Two: upload the new file and immediately load your homepage, one inner page and any page you redirected — three clicks. Three: if anything returns a 500 error, restore the backup at once and debug offline; a syntax error in this file takes the whole site down, not just one page, so never experiment directly on the live file. Four: test the redirects themselves (the old address should land on the new one in a single hop), then test the forced version — type the http and www variants and watch them settle on your chosen address. Five minutes of checking, and the file can be left alone for years.

What .htaccess cannot do

Knowing the limits saves real debugging time. The file cannot add HTTPS by itself — it can only redirect visitors to the secure version once a certificate exists. It cannot speed up a slow application or database; gzip and caching help delivery, but a page that takes five seconds to generate will still take five seconds to generate. It cannot protect a folder properly on its own either: hiding a directory listing is hygiene, not a lock, and anything genuinely private needs authentication or belongs outside the web root entirely. And it cannot fix a URL structure — redirects paper over moves, but a site that changes addresses every year will keep paying for it in lost links and confused visitors. Use .htaccess for what it is genuinely excellent at — canonical addresses, permanent redirects, sensible defaults and error handling — and solve the other problems where they actually live.

Frequently asked questions

Where does the .htaccess file go, and what is it called?

In your website's root folder (usually public_html), with the exact filename .htaccess — a leading dot and no extension. The dot makes it a hidden file on Linux systems, so enable 'show hidden files' in your file manager or FTP client if you cannot see it. Rules in it apply to that folder and everything below it.

My site shows a 500 error after adding .htaccess — what happened?

Almost always a syntax error or a module your server does not have enabled. Rename the file to htaccess.txt to disable it and confirm the site recovers, then add the blocks back one at a time to find the culprit. The rewrite blocks need mod_rewrite, compression needs mod_deflate and caching needs mod_expires — most shared hosts enable all three, but not all.

Does .htaccess work on every hosting type?

No — .htaccess is an Apache feature (including LiteSpeed, which reads the same rules). Nginx and Cloudflare-style static hosting ignore the file completely; the same jobs are done in the server block on Nginx or with redirect rules in your host's dashboard. This site, for example, runs on Cloudflare Workers and would not read an .htaccess file at all.

Should I force www or non-www?

Pick one and redirect the other to it — the choice itself matters far less than consistency, because search engines treat the two as separate sites until you consolidate them. Short non-www addresses are the modern default; very long domain names sometimes keep www to stay readable. If your SSL certificate only covers one version, force the covered one.

What is the difference between a 301 and a 302 redirect?

A 301 is permanent: browsers and search engines update their records and pass ranking value to the new address. A 302 is temporary and keeps the old address indexed. Every redirect this generator writes is a 301, because moved pages, HTTPS upgrades and www consolidation are all permanent changes. Use 302 only for genuinely temporary detours.

Why does forcing HTTPS sometimes cause a redirect loop?

Usually because the site sits behind a proxy or CDN that talks to your server over plain HTTP — the server sees an insecure connection and redirects, the proxy re-requests, and the cycle repeats. The fix is to make the CDN connect over HTTPS (flexible/full mode settings) or to check the X-Forwarded-Proto header instead. Also make sure your certificate actually covers the domain before forcing anything.

How do custom error pages work?

The ErrorDocument lines tell Apache which page to serve when an error occurs: your designed 404 page instead of the server's plain default. The paths are relative to the site root. The page itself is ordinary HTML — make it helpful, with your navigation and a search box, because a good 404 page rescues visitors who would otherwise leave.

Is it safe to edit .htaccess on a live site?

With one habit, yes: keep a backup copy of the current working file before every change (download it or copy it to htaccess-backup.txt in a non-public place). .htaccess takes effect instantly with no restart, which makes it powerful and unforgiving in equal measure — the backup is your undo button.

What does Options -Indexes do?

It stops Apache from showing an automatic listing of a folder's files when the folder has no index page. Without it, visitors (and scanners) can browse directories like /images/ or /backups/ and see every filename. It costs one line and closes a real information leak, which is why it is ticked by default in security checklists.

Related tools