不喜欢广告? 无广告 今天

Apache .htaccess Formatter & Validator

开发人员
广告 · 消除?
RewriteRule Flag Reference
Flag姓名描述
L最后的Stop processing further rules
R[=code]RedirectIssue an external redirect (default 302)
NCNo CaseCase-insensitive pattern matching
QSAQuery String AppendAppend query string to substitution URL
NENo EscapeDon't escape special characters in output
PTPass ThroughPass to next handler (useful with Alias)
PProxyForce proxy request for substitution
FForbiddenReturn 403 Forbidden response
GGoneReturn 410 Gone response
CChain current rule with the next rule
COCookieSet a cookie
EEnvSet an environment variable
HHandlerForce a content handler
N下一个Re-run rules from the start
NSNo SubrequestSkip rule for internal sub-requests
年代SkipSkip the next N rules
T类型Force MIME type
BEscape BackreferencesEscape non-alphanumeric backreference chars
DPIDiscard Path InfoDiscard PATH_INFO from rewritten URI
END结束Stop processing and don't apply more rules

RewriteCond sets a condition that must match before the next RewriteRule is applied. Syntax: RewriteCond TestString CondPattern [flags]. Multiple RewriteCond lines before a RewriteRule are combined with AND logic by default.

Common Snippets
广告 · 消除?

指导

Apache .htaccess Formatter & Validator

Apache .htaccess Formatter & Validator

Format and validate Apache .htaccess files with proper block indentation, syntax checking, and common error detection. Paste your .htaccess content and instantly see consistently formatted output with validation warnings for unclosed blocks, mismatched tags, invalid RewriteRule flags, and more. Includes common snippet templates and a RewriteRule flag reference.

如何使用

Paste your .htaccess content into the input area. The formatter processes it instantly — indenting block directives (IfModule, Directory, Files, etc.), normalizing comments, and validating syntax. Configure indent style (2 spaces, 4 spaces, or tabs), comment normalization, and blank line handling. Copy the formatted output or download it as an .htaccess file. Use the common snippets section to quickly insert standard configurations.

特征

  • Block Indentation — Automatically indents nested directives inside IfModule, Directory, Files, FilesMatch, Location, LocationMatch, Limit, VirtualHost, Proxy, RequireAll, RequireAny, and other Apache block directives.
  • 语法验证 — Real-time error detection: unclosed blocks, extra closing tags, mismatched block types, missing RewriteEngine directive, invalid RewriteRule flags. Color-coded with line numbers.
  • RewriteRule Flag Checking — Validates flags in RewriteRule directives against the full list of known Apache flags (L, R, NC, QSA, NE, PT, P, F, G, C, CO, E, H, N, NS, S, T, B, DPI, END).
  • Comment Handling — Preserves all comments with optional normalization (ensures space after #). Inline comments maintained in position.
  • Formatting Options — Configurable indent style (2 spaces, 4 spaces, tab), comment normalization toggle, blank line collapsing.
  • Common Snippets — Quick-insert templates: force HTTPS, trailing slash handling, custom error pages, IP blocking, GZIP compression, cache headers, directory listing prevention.
  • RewriteRule Reference — Collapsible reference table with all RewriteRule flags and their descriptions, plus RewriteCond/RewriteRule syntax guide.
  • Export — Copy formatted output or download as .htaccess file.

Validation Checks

Block matching: Every opening block tag must have a corresponding closing tag of the same type. RewriteEngine: Warns if RewriteRule or RewriteCond directives are used without RewriteEngine On. Flag validation: Checks RewriteRule flags against known Apache mod_rewrite flags. Duplicate detection: Alerts when the same directive appears multiple times (may be intentional but worth reviewing).

广告 · 消除?

What is an .htaccess file?

An .htaccess (hypertext access) file is a directory-level configuration file for Apache HTTP Server. It allows you to override server configuration on a per-directory basis without editing the main httpd.conf. Common uses include URL rewriting (pretty URLs, redirects), access control (password protection, IP blocking), custom error pages, MIME type configuration, and caching headers. The file is named .htaccess (with a leading dot) and is placed in the directory you want to configure.

What are the most common RewriteRule flags?

The most frequently used flags are: [L] (Last — stop processing rules), [R=301] (Redirect — send HTTP redirect, 301 for permanent), [NC] (No Case — case-insensitive matching), [QSA] (Query String Append — preserve existing query string), [NE] (No Escape — don’t encode special characters), [P] (Proxy — handle via mod_proxy), [F] (Forbidden — return 403), and [END] (like L but also prevents further .htaccess processing in subdirectories). Multiple flags are combined with commas: [L,R=301,NC].

Why does my .htaccess redirect loop?

Redirect loops usually happen when a RewriteRule matches its own output. For example, redirecting all requests to HTTPS will loop if the rule doesn’t check whether the request is already HTTPS. Always add a RewriteCond before redirect rules: RewriteCond %{HTTPS} off (for HTTPS redirects) or RewriteCond %{REQUEST_URI} !^/target (to exclude the target path). Also check for conflicting rules — multiple redirect rules can create circular references. The [L] flag helps by stopping rule processing after a match.

Is my .htaccess content sent to a server?

No — all formatting and validation happens in your browser using JavaScript. Your .htaccess content never leaves your device. This is important because .htaccess files can contain sensitive configuration: access control rules, internal paths, IP addresses, and security settings. All processing runs entirely client-side with no API calls or data storage.

想要享受无广告的体验吗? 立即无广告

安装我们的扩展

将 IO 工具添加到您最喜欢的浏览器,以便即时访问和更快地搜索

添加 Chrome 扩展程序 添加 边缘延伸 添加 Firefox 扩展 添加 Opera 扩展

记分板已到达!

记分板 是一种有趣的跟踪您游戏的方式,所有数据都存储在您的浏览器中。更多功能即将推出!

广告 · 消除?
广告 · 消除?
广告 · 消除?

新闻角 包含技术亮点

参与其中

帮助我们继续提供有价值的免费工具

给我买杯咖啡
广告 · 消除?