404 Redirect
Syntax
{
"Key": "redirect:on:404",
"Value": {
"Type": "page_redirect|url_redirect|trigger_callback|login_redirect|default",
"PageSlug": "string",
"PageId": "numeric",
"Url": "string",
"Callback": "string",
"Code": "numeric"
}
}
The properties PageSlug, PageId, Url, and Callback are required depending on the selected Type. For instance, if url_redirect type is chosen, then the Url property must also be provided.
For the Code property, these are the accepted HTTP status codes, depending on the Type:
default: does not accept codepage_redirect: 3xxurl_redirect: 3xxlogin_redirect: does not accept codestrigger_callback: 3xx, 4xx, 5xx
Examples
The following policy redirects user to a page with ID 43.
{
"Param": [
{
"Key": "redirect:on:404",
"Value": {
"Type": "page_redirect",
"PageId": 43
}
}
]
}
Definition
The 404 redirect behavior is expressed in the AAM access policy as the param redirect:on:404. The Value property contains attributes that define how to handle redirects.
The Type attribute defines what type of redirect to apply and can contain one of the following values:
page_redirectis the redirect to an existing page.url_redirectis the safe redirect to a URL.trigger_callbackinvokes a custom PHP function that handles redirects.login_redirectredirects user to the login page if user is not authenticated and then redirects back upon successful login.defaultis the default WordPress behavior.
Depending on the Type additional information may be required to fine-tune the redirect as follows:
- If the redirect type is
page_redirect, you can provide either the page slug or page ID for the destination page. We recommend using page slugs to make policies more readable. - If the redirect type is
url_redirect, you should provide a valid URL. However, AAM uses WordPress core safe redirect for security and compliance reasons. You can learn more about this from What is a safe redirect in WordPress? blog. - If the redirect is a
trigger_callback, a valid PHP callback function is required. AAM does not validate if the provided function exists.
Here is an example of the “404 redirect” param where we redirect a user to a custom 404 page.
{
"Param": [
{
"Key": "redirect:on:404",
"Value": {
"Type": "page_redirect",
"PageSlug": "custom-404"
}
}
]
}