PhoenixKit.WebsiteAccess.Redirect (phoenix_kit v2.26.0)

Copy Markdown View Source

Redirect to production: a visitor's request for a public URL goes to the same path on the configured production site.

Smart on purpose — this site is where the agency works, so nobody who is meant to be here is sent away: a logged-in user is not redirected, a path under the admin prefix is not (the admin came here to do admin work), the gate page and assets are not. Scope narrows it further: "everyone", or "crawlers" — only search-engine crawlers, by user agent — so a staging site can keep its humans and lose its index.

A 302, never a 301: browsers cache a 301, and this is temporary by nature.

Summary

Functions

Whether user_agent looks like a search-engine crawler.

Where conn should be sent, or nil when it stays. logged_in? is decided by the caller (the plug already resolves the session user for maintenance).

The production URL parsed and checked: http(s), a host, no userinfo, no query, no fragment, no whitespace or control characters; the path (if any) is kept as a prefix without its trailing slash. Nil otherwise.

The production URL, normalised without a trailing slash; nil when unset or not http(s).

Functions

crawler?(user_agent)

@spec crawler?(String.t() | nil) :: boolean()

Whether user_agent looks like a search-engine crawler.

enabled?()

@spec enabled?() :: boolean()

enabled_key()

scope()

@spec scope() :: String.t()

scope_key()

scopes()

switched_on?()

@spec switched_on?() :: boolean()

target_for(conn, opts \\ [])

@spec target_for(Plug.Conn.t(), keyword()) :: String.t() | nil

Where conn should be sent, or nil when it stays. logged_in? is decided by the caller (the plug already resolves the session user for maintenance).

target_uri()

@spec target_uri() :: URI.t() | nil

The production URL parsed and checked: http(s), a host, no userinfo, no query, no fragment, no whitespace or control characters; the path (if any) is kept as a prefix without its trailing slash. Nil otherwise.

target_url()

@spec target_url() :: String.t() | nil

The production URL, normalised without a trailing slash; nil when unset or not http(s).

url_key()