Redirect first-match flow
Overview
TheRedirect section allows SafeSquid to intercept requests for specific URLs and either internally rewrite them (fetching content from a new destination on behalf of the client) or send an HTTP 302 redirect back to the client’s browser.
Core Mechanics (C++ Source Validation)
First-match URL/Location rewrite, send302 branching.- Evaluation Order: Rules are evaluated top to bottom. The first matching rule takes effect and evaluation stops for that pass.
- PCRE Matching: The
URLfield accepts Perl Compatible Regular Expressions (PCRE) with capture groups (e.g.,(.*)), which can be referenced in theRedirectfield using$1,$2, etc. - Internal Rewrite vs. 302: If
send302is false, SafeSquid fetches the rewritten URL and serves the content transparently. If true, it returns an HTTP 302 Location redirect to the client.
Schema Fields
Global Fields
- Enabled (enabled): Toggles URL redirection globally.
Rule-Based Fields (Per Connection Tuning)
- Enabled (enabled): Toggles the rule.
- Comment (comment): User description. Logged on match when non-empty.
- Profiles (profiles): The trigger condition. Limit this entry to connections that already carry these Access Profile tags.
- URL (url): PCRE matched against the request URL or Location header.
- Redirect (redirect): The replacement template after the PCRE match.
- Port (port): When > 0, forces this destination port on internal rewrite.
0keeps the port from the rewritten URL. - 302 redirect (send302): Set to
Yesfor HTTP 302, orNofor internal transparent fetch. - Options (options): Bitmask/list of options: Decode URL before match (
DECODEBEFORE), encode URL path (ENCODE), or decode URL path after substitution (DECODEAFTER). - Applies to (which): Match client request URL (
URL), response Location header (LOCATION), or both (BOTH).
How SafeSquid processes the list
- On the client request, SafeSquid builds
proto://host/fileand tests rows whose Applies to includes URL (or BOTH). - On redirect responses, SafeSquid tests the response
Locationvalue for rows that include LOCATION (or BOTH). - First enabled row that matches profiles, URL regex, and direction wins; processing stops.
- 302 redirect = No (default): rewrite
proto,host,file, and optional port on the request and fetch internally; request type may become HTTP proxy. - 302 redirect = Yes: send HTTP 302 to the client with the rewritten URL as Location; no origin fetch for that request.
- Options: percent-decode before PCRE match; URL-encode or decode the path portion after substitution.
Important entry fields
- Profiles — Apply only when the connection has one of these profiles. Blank = all connections. Prefix
!to skip connections that have a profile. - URL — PCRE with capture groups matched against the request URL or Location header. Required; blank URL skips the row.
- Redirect — Replacement template after PCRE match (supports
$1captures and connection variables). - Port — When > 0, force this destination port on internal rewrite. 0 keeps the port from the rewritten URL.
- 302 redirect — Yes — HTTP 302 to client. No — internal rewrite and fetch.
- Applies to — URL (request only), LOCATION HEADER (response redirects only), or BOTH (separate processing passes).
Examples
Open Configure → Real time content security → Redirect → Redirection policies. Row fields are Enabled, Comment, Profiles, URL, Redirect, Port, 302 redirect, and Applies to — the shipped default rows enforce safe search on Bing, Google, Yahoo, and DuckDuckGo.Redirect — Redirection policies rows
How to verify
- Reproduce the URL from a client and watch whether the browser receives 302 or content from the rewritten host.
- Enable REDIRECT in
LOG_LEVELfor native lines showing match, internal rewrite, or an HTTP 302. - Open Reports → Detailed logs for the requested URL and response code.
- Pair Redirect profile tags with rows in Access Profiles (tags are not hard-coded — both sections must reference the same tag string).

