After enabling it from the modules section an warning/error message is displayed.

Warning: parse_url(http://) [function.parse-url]: Unable to parse URL in domain_301_redirect_init() (line 67 of /public_html/sites/all/modules/domain_301_redirect/domain_301_redirect.module).

It seems to be an error indicating that the domain hasn't been set. Maybe a "pretty message" should be displayed notifying the user that they need to set the domain.

Also, the message goes away after you set the domain.

Comments

jeremyr’s picture

In domain_301_redirect.module I replaced this starting on line 59

function domain_301_redirect_init() {
  // Don't redirect when using drush
  if (!drupal_is_cli()) {
    $domain_301_redirect_enabled = variable_get('domain_301_redirect_enabled', false);
    $domain_301_redirect_domain = variable_get('domain_301_redirect_domain', '');
    if (!preg_match('|^https?://|', $domain_301_redirect_domain)) {
      $domain_301_redirect_domain = 'http://' . $domain_301_redirect_domain;
    }
    $parsed_domain = parse_url($domain_301_redirect_domain, PHP_URL_HOST);
    if ($domain_301_redirect_enabled && !empty($domain_301_redirect_domain) && $parsed_domain != $_SERVER['HTTP_HOST'] && !user_access('bypass domain 301 redirect')) {
      drupal_goto($domain_301_redirect_domain . $_SERVER['REQUEST_URI'], array(), 301);
    }
  }
}

With this:

function domain_301_redirect_init() {
  // Don't redirect when using drush
  if (!drupal_is_cli()) {
    $domain_301_redirect_enabled = variable_get('domain_301_redirect_enabled', false);
    $domain_301_redirect_domain = variable_get('domain_301_redirect_domain', '');
    if (!preg_match('|^https?://|', $domain_301_redirect_domain)) {
      $domain_301_redirect_domain = 'http://' . $domain_301_redirect_domain;
    }
    if (preg_match('|^https?://[a-z0-9.]+.*|', $domain_301_redirect_domain)) {
      $parsed_domain = @parse_url($domain_301_redirect_domain, PHP_URL_HOST);
      if ($domain_301_redirect_enabled && !empty($domain_301_redirect_domain) && $parsed_domain != $_SERVER['HTTP_HOST'] && !user_access('bypass domain 301 redirect')) {
        drupal_goto($domain_301_redirect_domain . $_SERVER['REQUEST_URI'], array(), 301);
      }
    }
    elseif (variable_get("domain_301_redirect_enabled", FALSE)) {
      drupal_set_message(t("Domain is not set"), "warning");
    }
  }
}
jessebeach’s picture

Hi jeremyr, I addressed these warning messages in the 7.x-1.0 release. Rather than suppressing the error with @, I moved if statements around so parse_url isn't called if we don't have $domain_301_redirect_domain.

jessebeach’s picture

Status: Active » Closed (fixed)