function _prod_check_www in Production check & Production monitor 6
Same name and namespace in other branches
- 7 prod_check.module \_prod_check_www()
File
- ./prod_check.module, line 1838
Code
function _prod_check_www($caller = 'internal') {
global $base_url;
$check = array();
$error = FALSE;
$redirect_code = 0;
$url = $original = $base_url . base_path();
$www = '://www.';
if (stripos($url, $www) !== FALSE) {
$url = str_replace($www, '://', $url);
}
else {
$url = str_replace('://', $www, $url);
}
$result = drupal_http_request($url);
if ($result->code > 0) {
if (isset($result->redirect_code)) {
$redirect_code = $result->redirect_code;
}
else {
$error = TRUE;
}
$check['prod_check_www'] = array(
'#title' => t('WWW redirect'),
'#state' => !$error,
'#severity' => $caller == 'nagios' ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
'#value_ok' => t('WWW redirect setup correctly!'),
'#value_nok' => t('No WWW redirect found!'),
'#description_ok' => t('WWW redirect properly setup: %url redirects to %original with HTTP status code %code.', array(
'%url' => $url,
'%original' => $original,
'%code' => $redirect_code,
)),
'#description_nok' => t("You should make sure you setup an HTTP redirect with status code 301 from %url to %original (or vice versa) to prevent duplicate content punishment by search engines such as Google.<br />You can do this easily by uncommenting the right block in Drupal's .htaccess file.", array(
'%url' => $url,
'%original' => $original,
)),
'#nagios_key' => 'WWWR',
'#nagios_type' => 'state',
);
return prod_check_execute_check($check, $caller);
}
}