Matching Redirects

When you create a redirect it always has at the very least a source URL. You can also optionally configure other details to determine if a request is matched.

  • URL only – the source URL must match the requested page URL. This is the basic redirect
  • URL and login status – the user’s login status is used to determine the match, in addition to the source URL
  • URL and role/capability – similar to login status, but a logged in user’s role or capability is used to determine the match, as well as the source URL
  • URL and referrer – the user’s referrer (their previous URL) is used to determine the match, in addition to the source URL
  • URL and user agent – the browser user agent is used to determine the match, in addition to the source URL
  • URL and cookie – a cookie is used to determine the match, in addition to the source URL
  • URL and server – the server name is used to determine the match, in addition to the source URL
  • URL and HTTP header – an HTTP header is used to determine the match, in addition to the source URL
  • URL and custom filter – a custom WordPress filter is used to determine the match, in addition to the source URL

Each match type always requires a source URL. You can optionally enabled the regex option to use a regular expression. This will allow you to match against a range of URLs by defining a regular expression pattern. More details on the regular expression page.

URL and Login Status

This uses the user’s login status to determine the match. It allows you to redirect the user to different URLs depending on whether they are logged in or out.

When enabled you are shown two options:login_status_match

  • Logged In – target URL when the source URL is matched and the user is logged in
  • Logged Out – target URL when the source URL is matched and the user is not logged in

Leaving one of these blank means that the logged in/logged out status is not used for this particular match.

URL and Role/Capability

This uses the logged in user’s role or capability. For example, you can redirect admin users, or editors, or user’s with a particular custom capability.

When enabled you are shown three options:

  • Role– the name of a WordPress role or capability
  • Matched Target – target URL when the source URL is matched and the user’s role or capability matches
  • Unmatched Target – target URL when the source URL is matched and the user’s role or capability does not match

Leaving one of these blank means that the logged in/logged out status is not used for this particular match. Note that logged out user’s will not match.

URL and Referrer

This uses the user’s ‘referrer’ URL in addition to the source URL to determine the match. A referrer URL is sent when someone visits your URL after following a link from another page. For example, if the user is on http://myexample.com/page and clicks a link to http://yoursite.com/other-page then the referrer will be http://myexample.com/page.

Note that the referrer information is not guaranteed to be sent by the browser.

When enabled you are shown three options:

referrer_action

  • Referrer – the pattern used to match the referrer URL. You can use the regex option to enable pattern matching
  • Matched Target – target URL when the source URL and referrer matches
  • Unmatched Target – target URL when the source URL matches but the referrer doesn’t

Leaving matched or unmatched blank means that particular condition is not used.

URL and User Agent

This uses the user’s browser agent in addition to the source URL to determine the match. A browser agent is sent by your browser to identify itself. It includes information about the operating system (Windows, MacOS etc) and the browser (IE, Firefox, Chrome etc).

You can use this match to redirect the user based on their browser. For example, all mobile users could be redirected to a particular page, and non-mobile to another page.

When enabled you are shown three options:

  • User Agent – the pattern used to match the user agent. You can use the regex option to enable pattern matching, and the Custom dropdown to use a predefined pattern.
  • Matched Target – target URL when the source URL and the user agent matches
  • Unmatched Target – target URL when the source URL matches but the user agent doesn’t

Leaving matched or unmatched blank means that particular condition is not used.

URL and server

This matches against the server name in addition to the source URL. This is useful if you have a subdomain or other domain that points to the same server as your main domain, and you want to redirect only on the other domain.

When enabled you are shown these options:

  • Server – the domain name of the server
  • Matched target – target URL when the source URL and server matches
  • Unmatched target – target URL when the source URL and server doesn’t match

Leaving matched or unmatched blank means that particular condition is not used.

URL and cookie

This matches against a cookie in addition to the source URL. For example, you can check if a tracking, user login, or any other kind of custom cookie exists.

When enabled you are shown these options:

  • Cookie name – the name of the cookie. Case is not important
  • Cookie value – the value of the cookie. Use the regex checkbox for a regular expression match
  • Matched target – target URL when the source URL and the cookie matches
  • Unmatched target – target URL when the source URL matches but the cookie doesn’t

Leaving matched or unmatched blank means that particular condition is not used.

URL and HTTP header

This matches any HTTP header in addition to the source URL. You can use this for custom redirects that match any HTTP header for example such as browser language.

When enabled you are shown these options:

  • HTTP header – the name of the header. Case is not important. Use the header name as passed via HTTP, including hyphen
  • HTTP header value – the value of the header. Use the regex checkbox for a regular expression match
  • Matched target – target URL when the source URL and the HTTP header matches
  • Unmatched target – target URL when the source URL matches but the HTTP header doesn’t

Note it is your responsibility to ensure your web server is passing the HTTP headers to PHP via HTTP_X in $_SERVER values. Some servers need additional configuration, and this is not something Redirection has control over.

Leaving matched or unmatched blank means that particular condition is not used.

URL and custom filter

When the URL matches a custom WordPress filter is fired, and you can use this to add your own matching logic. You would use this for custom situations where you cannot represent the match using other means.

When enabled you are shown these options:

  • WordPress filter name – the name of the filter you want to fire. Ensure it doesn’t clash with anything else. The filter will be passed two parameters: false and $url. The filter should return true if your logic is a match, and false otherwise
  • Matched target – target URL when the source URL matches and the filter returns true
  • Unmatched target – target URL when the source URL matches and the filter returns false (the default value)

Note the custom code is your responsibility. You will need familiarly with PHP and WordPress. An example is shown below:

add_filter( 'my_custom_filter', function( $result, $url ) {
  if ( my_custom_logic() ) {
    return true;
  }

  return false;
}, 10, 2 );
search previous next tag category expand menu location phone mail time cart zoom edit close