What is F flag in htaccess rewrite rule
The F flag in a RewriteRule stands for [F]orbidden. When this flag is used, Apache immediately stops processing rules and returns a 403 Forbidden status code to the client. Apache HTTP Server
This flag is useful for blocking access to specific files, file types, or directory paths without needing to use a formal Deny directive. Apache HTTP Server
Key Aspects of the [F] Flag
- Implies [L] (Last): When you use
[F], an[L]flag is automatically implied, meaning it returns the 403 status immediately and stops further rule evaluation. - Use with “-“: When using the
[F]flag, you typically use a hyphen (-) as the rewrite target instead of a URL. The hyphen tells mod_rewrite not to change the URI, as the request is being blocked anyway. - Example: To forbid access to all
.exefiles on your server, you can use:apacheRewriteRule "\.exe" "-" [F]This rule matches any URL ending in.exeand returns a 403 Forbidden error.Apache HTTP Server +2
[F]orbidden vs. [G]one
- [F] (Forbidden): Tells the browser that access to this resource is prohibited (403), regardless of whether it ever existed.
- [G] (Gone): Tells the browser that the resource existed in the past but is no longer available (410).
Apache HTTP Server
One Comment