Configuration: routing and URL processing
This page documents directives that affect HTTP request matching and configuration layering inside host blocks. The http-server module’s radix tree resolver processes these directives.
For the full request order, see Request pipeline order. Ferron resolves host, location, and if blocks once per request, before any pipeline stage runs.
Directives#
Path matching#
location <path: string>- This directive specifies a path prefix for request matching.
/apimatches/apiand/api/.... Longer matches are more specific. If this block matches, Ferron automatically rewrites the URL to remove the base URL. Default: not configured
- This directive specifies a path prefix for request matching.
Configuration example:
example.com {
location /api {
# Configuration for /api paths
}
}- Matching is prefix-based (
/apimatches/apiand/api/users). More specific locations win over less specific ones. - If this block matches, Ferron automatically rewrites the URL to remove the base URL.
- Ferron supports prefixes only. There is no regex form such as
location ~. Use amatchblock withiforif_notfor pattern routing. See Conditionals and variables. - Ferron selects the
locationblock once, on the original URL, before pipeline stages run. A laterrewritedoes not move the request to a differentlocationblock. See Request pipeline order.
Inheritance#
A location block inherits directives from the enclosing host block and from global defaults. When the same directive appears at both levels, the value in the location block wins for requests in that block. The same rule applies to if and if_not blocks nested in a host or location block.
Conditional matching#
if <matcher-name: string>- This directive specifies a named matcher to evaluate. When the named matcher evaluates to true, Ferron applies the nested block’s directives. Default: not configured
if_not <matcher-name: string>- This directive specifies a named matcher to evaluate. When the named matcher evaluates to false, Ferron applies the nested block’s directives. Default: not configured
Configuration example:
example.com {
if api_request {
# Applied when api_request matcher passes
}
if_not api_request {
# Applied when api_request matcher fails
}
}For named matcher syntax and available variables, see Conditionals and variables.
Error handling#
handle_error [status: integer]- This directive associates a nested block with a specific error code, or with a default error case when you give no code. Default: not configured
Configuration example:
example.com {
handle_error 404 {
# Custom handling for 404 errors
}
}URL redirects#
trailing_slash_redirect [bool: boolean]- This directive specifies whether automatic 301 redirects from directory paths without a trailing slash to the same path with a trailing slash are enabled. When omitted, defaults to
true. Default:trailing_slash_redirect true
- This directive specifies whether automatic 301 redirects from directory paths without a trailing slash to the same path with a trailing slash are enabled. When omitted, defaults to
Configuration example:
example.com {
root /srv/www/example
trailing_slash_redirect
}Notes for trailing_slash_redirect:
- Only applies when the resolved request path maps to a directory on the filesystem.
- Ferron preserves query strings in the redirect (for example
/blog?foo=bar→/blog/?foo=bar). - This is useful for SEO consistency and for making sure relative links within directory-served pages resolve correctly.