Using Custom Rules in the Redirection Manager

In this article we'll explain how to use the Custom Rules options in our Redirection Manager.

Using Custom Rules

To use this feature, go to Redirects in the All in One SEO menu.

Redirects menu item shown in the All in One SEO menu

You'll see the Add New Redirect form.

Add New Redirect form in the Redirection Manager in All in One SEO

In the Source URL field, enter the URL you want to redirect from. The URL must be a relative URL, i.e. don't include the https://mydomain.com part of your URL.

Source URL field in the Add New Redirection form

In the Target URL field, enter the URL you want to redirect to. The URL can be either a relative URL or an absolute URL.

Target URL field in the Add New Redirection form

You can also start typing the title of any post, page or other content on your site, or the slug or ID in the Target URL field and the matching content will be displayed. Click on the post or page you want to select as your target.

Now click on the Advanced Settings toggle to display the Custom Rules fields.

Custom Rules fields in the Add New Redirect form

You'll see a drop down where you can select the rule type, and a field where you can enter the value to match on.

Here's an explanation of each of the rule types:

Login Status

Use this option to match redirects by the user login status. You can redirect a visitor if they're either Logged In or Logged Out of your site.

Login Status selected in the Custom Rules fields

WordPress User Roles

Use this option to match redirects by the user role for logged in users. You can set multiple roles like Author and Editor to match one or the other.

WordPress User Roles selected in the Custom Rules fields

Referrer

Use this option to match redirects by the referrer. Click on the Regex toggle to use regex to match the values.

Referrer selected in the Custom Rules fields

User Agent

Use this option to match redirects by the user agent. Click on the Regex toggle to add your own values or use our predefined options.

User Agent selected in the Custom Rules fields

Here's an explanation of our predefined options:

  • Mobile: This option will regex match any of these mobile user agents:
iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-Md+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS
  • Feeds: This option will regex match any of these feed user agents:
Bloglines|feed|rss
  • Libraries: This option will regex match any of these library user agents:
cURL|Java|libwww-perl|PHP|urllib

Use this option to match redirects to cookies. Click on the Regex toggle to use regex to match the values.

Cookie selected in the Custom Rules fields

IP Address

Use this option to match redirects by IP address.

IP selected in the Custom Rules fields

Click on the Regex toggle to use regex to match the values.

IP rule with regex in the Custom Rules fields

Server

Use this option to match redirects to a server. Click on the Regex toggle to use regex to match the values.

Server selected in the Custom Rules fields

HTTP Header

Use this option to match redirects to a HTTP header. Click on the Regex toggle to use regex to match the values.

HTTP Header selected in the Custom Rules fields

WordPress Filter

Use this option to set custom filters. The filter name will be executed when trying to match a redirect.

WordPress Filter selected in the Custom Rules fields

The filter return value will always be ‘false' meaning the filter will never match. Use the filter and return a ‘true' value to have the rule match.

add_filter( 'aioseo_custom_filter', function ( $match, $url, $redirect ) {
if ( ! empty( $_GET['do-redirect'] ) ) {
$match = true;
}

return $match;
}, 10, 3 );

Locale

Use this option to match redirects to a locale. Click on the Regex toggle to use regex to match the values.

Locale selected in the Custom Rules fields

Multiple Rules

You can add multiple rules combining any of the above by clicking on the Add Custom Rule button.

Multiple rules will behave as an AND match.

Example: The Login Status and Locale rule below will match as: Use is Logged In AND their Locale is en_GB.

Example showing multiple custom rules