Ejemplo n.º 1
0
 function template_redirect()
 {
     // Load data
     $modules = Red_Module::get_by_type('wp');
     if (count($modules) > 0) {
         foreach ($modules as $wp) {
             // Timeout
             if ($wp->time_limit != 'default') {
                 set_time_limit($wp->time_limit);
             }
             // Error level
             if ($wp->error_level == 'none') {
                 error_reporting(0);
             } else {
                 if ($wp->error_level == 'show') {
                     error_reporting(E_ALL);
                 }
             }
             // Mangle the URL, if needed
             $url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
             $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
             $original = $url;
             if ($wp->canonical == 'www') {
                 $url = preg_replace('@(https?)://(www)?\\.?@', '$1://www.', $url);
             } else {
                 if ($wp->canonical == 'nowww') {
                     $url = preg_replace('@(https?)://(www)?\\.?@', '$1://', $url);
                 }
             }
             if ($wp->strip_index == 'yes') {
                 $url = preg_replace('@index.(htm|html|php|asp|aspx|jsp)@', '', $url);
             }
             if ($url != $original) {
                 wp_redirect($url, 301);
             }
             if ($this->matched) {
                 $this->matched->action->process_after($this->matched->action_code, $original);
             }
         }
     }
 }
Ejemplo n.º 2
0
 function template_redirect()
 {
     global $redirection;
     if (is_404() && !$redirection->hasMatched()) {
         $url = $_SERVER['REQUEST_URI'];
         $redirects = Red_Item::get_for_url($url, '404');
         if (!empty($redirects)) {
             foreach ($redirects as $key => $item) {
                 if ($item->matches($url)) {
                     $redirection->setMatched(true);
                     $this->matched = $item;
                     break;
                 }
             }
         }
         if (empty($this->matched)) {
             $modules = Red_Module::get_by_type('404');
             if (count($modules) > 0) {
                 foreach ($modules as $module) {
                     // Log 404 errors
                     if ($module->log_404) {
                         if (isset($_SERVER['REMOTE_ADDR'])) {
                             $myip = $_SERVER['REMOTE_ADDR'];
                         } else {
                             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                                 $myip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                             }
                         }
                         $options = $redirection->get_options();
                         if ($options['log_404s']) {
                             $log = RE_Log::create($_SERVER['REQUEST_URI'], '', $_SERVER['HTTP_USER_AGENT'], $myip, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', 'NULL', $module->id);
                         }
                     }
                 }
             }
         }
     }
 }