# CWP .htaccess Generator

> Generate a working Apache .htaccess file: force HTTPS, pick www or non-www, add redirects, set cache headers, block hotlinking and stop directory listings.

Source: https://cwp.sg/tools/htaccess-generator/  
Last verified: 2026-08-04

**In short:** CWP .htaccess Generator is a free browser-based tool at https://cwp.sg/tools/htaccess-generator/ — no signup, no rate limit, and it works with no network connection.

## Why generated rules beat copied ones

Most `.htaccess` problems come from pasting two snippets that each work alone and fight each other together. The classic is two HTTPS redirects — one from your control panel, one from a tutorial — producing [ERR_TOO_MANY_REDIRECTS](/errors/err-too-many-redirects/).

The HTTPS rule here includes a condition most snippets leave out:

```apache
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
```

Without it, any proxy in front of your site — Cloudflare, a load balancer, your host's edge — terminates TLS, forwards the request as plain HTTP, and your server redirects to HTTPS forever. That one line is the difference between a working redirect and an infinite loop.

## Where the file goes

In your web root, next to `index.php`. Name it exactly `.htaccess` — with the leading dot and no extension. Some FTP clients hide dotfiles; enable "show hidden files" if you can't see it.

Rules are inherited. An `.htaccess` in a parent directory applies to everything beneath it, which is worth remembering when a rule seems to fire on a page you never configured.

## If it breaks the site

A bad directive gives you [500 Internal Server Error](/errors/500-internal-server-error/) on every page in that directory and below.

Rename the file rather than deleting it:

```
mv .htaccess .htaccess.bak
```

If the site returns, the file is the cause. Restore it and comment out half the rules, reload, and repeat until you find the line. On WordPress, if you deleted the file instead, regenerate the default rules from **Settings → Permalinks → Save**.

## A note on nginx and LiteSpeed

LiteSpeed reads `.htaccess` natively, so these rules work unchanged. **nginx does not read `.htaccess` at all** — if your host runs plain nginx, these rules will be silently ignored and you need the equivalent `server` block instead. Ask your host which server they run before spending an afternoon debugging a file nothing is reading.

---

Content Website Platform (cwp.sg) operates the free hosting it writes about; see https://cwp.sg/about/ for the methodology and the commercial disclosure.
