🛡️

Apache .htaccess Generator

Generate Apache rules for HTTPS, headers, cache, IP, proxy, conflicts, score and redirect simulation.
Apache 📂 Developer 👤 ToolCMS 🏷️ v1.5.3 ⚙️ clipboard
Apache 2.4 · 配置生成

把重定向、安全头与缓存写成规则

按站点域名和需求生成可审阅的 .htaccess:HTTPS 与 www 规范、安全响应头与 CSP、压缩缓存、404、防盗链、IP 限制、Basic Auth 与 WordPress 固定链接。冲突会先提示,不直接覆盖线上文件。

站点与跳转

先定规范域名

安全响应头

mod_headers

性能与错误页

按需启用

访问限制

默认不锁死自己

等待配置。规则只在浏览器内生成,不会上传或写入服务器。

规则预览

未生成
# 还没有生成规则
# 点“载入示例”或勾选选项后点“生成规则”
规则行—
模块—
字节—

部署前模拟

验证跳转目标,不请求服务器
根据当前生成规则,计算首个跳转与目标 URL。

跳转链体检

循环、重复、遮蔽与 HSTS preload
生成规则后检查自定义跳转链与 preload 前置条件。

CSP 强度体检

指令覆盖与不安全来源
生成 CSP 后检查对象源、脚本源、frame-ancestors 与报告模式。

冲突与部署检查

未评分先处理冲突再上传
生成后显示 6 项检查。

How to Use

📖 What it does

Most .htaccess incidents are not exotic: a redirect points at another redirect, a module is missing, or HSTS is enabled before every subdomain has a certificate. The generator exists to expose those conflicts before the file reaches production.

This page builds Apache 2.4 text from a site host and a set of options. It never uploads or writes to a server, and it does not create passwords, certificates or Nginx rules. The output is meant to be reviewed, tested and versioned.

A generated file is a draft. Apache reads .htaccess per request, so a syntax error can return 500 for the whole site. Back up the original, run configtest in staging and verify with curl before replacing the live file.

✨ Features

  • Combine HTTPS and www canonicalisation into as few 301 hops as possible, support X-Forwarded-Proto behind a proxy, avoid www.www targets, and warn when rules could point at each other.
  • Write HSTS, CSP, nosniff, frame options, referrer policy and permissions policy only when selected, with notes on subdomain, preload and breakage risk.
  • Generate mod_deflate compression and mod_expires one-year cache blocks, with a reminder that HTML and API responses need a different policy.
  • Add a custom 404, image hotlink protection, IP/CIDR blacklist or allowlist, Basic Auth with an absolute .htpasswd path, WordPress permalink rewrites and a CSP preset.
  • Emit an Apache 2.4 RequireAny allowlist and skip the block when the list is empty, so an empty or malformed list cannot silently deny every visitor.
  • Validate hostname, path, CIDR, auth path and redirect format, then report line count, byte size and the modules the rules depend on.

🚀 How to use it

  1. Enter the site hostname first; without it the page cannot generate a www canonical rule.
  2. Select HTTPS, canonical host, security headers, HSTS, CSP, compression, cache, 404, hotlink, IP limits or WordPress as needed.
  3. For Basic Auth, provide the absolute .htpasswd path and create the password file on the server, never inside the web root.
  4. Click Generate, resolve every red conflict, then copy or download the .htaccess and the deployment notes.
  5. Start with CSP Report-Only, watch the browser console for blocked resources, then switch to enforcement; run apachectl configtest in staging and curl the HTTP, HTTPS, www, non-www and 404 URLs before production.

⚠️ Before you rely on it

  • A missing mod_rewrite, mod_headers, mod_filter, mod_deflate or mod_expires makes the matching IfModule block a no-op; the page cannot detect installed modules.
  • HSTS is remembered by the browser for the max-age. includeSubDomains can lock out a subdomain without a valid certificate, and preload removal is slow.
  • Basic Auth over HTTP sends credentials in clear text; pair it with HTTPS and keep .htpasswd outside the web root.
  • A one-year cache belongs on versioned assets, not HTML or API JSON; a CDN may override the origin Expires header.
  • Test redirects with 302 first when the target is uncertain. A 301 is cached by browsers and harder to undo during an incident.
  • Keep one canonical host decision for the whole site, including the CDN and the application configuration. A rule that only fixes Apache while the CDN rewrites the host can still produce two different public URLs for the same page.

Related

⏫︎