1 redirect.module redirect_can_redirect()

Check the ability to perform redirects with the current request context.

This function checks the following conditions:

  • If the PHP entry point is the root index.php file.
  • If PHP is not running as CLI.
  • If the site is not offline or in install/update mode.
  • If the current page is not an admin page (check can be disabled).
  • If the current request does not have any POST data since a redirect may interrupt form submission.

Return value

bool: TRUE if redirects can be performed, or FALSE otherwise.


core/modules/redirect/redirect.module, line 1018


function redirect_can_redirect() {
  $can_redirect = &backdrop_static(__FUNCTION__);
  if (!isset($can_redirect)) {
    $can_redirect = TRUE;

    if ($_SERVER['SCRIPT_NAME'] != $GLOBALS['base_path'] . 'index.php') {
      // Do not redirect if the root script is not /index.php.
      $can_redirect = FALSE;
    elseif (!empty($_POST)) {
      // Do not redirect if this is a post request with data.
      $can_redirect = FALSE;
    elseif (backdrop_is_cli()) {
      // If this is a command line request (Drush, etc), skip processing.
      $can_redirect = FALSE;
    elseif ((state_get('maintenance_mode', 0) || defined('MAINTENANCE_MODE')) && !user_access('access site in maintenance mode')) {
      // Do not redirect in offline or maintenance mode.
      $can_redirect = FALSE;

  return $can_redirect;