Ответы пользователя по тегу Apache HTTP Server
  • Как сделать редирект на основную страницу wordpress исключив дубли?

    @TraiDeR
    Можно решить проблему бесконечного дублирования страниц в wordpress, просто встроить следующих код в functions.php вашей темы:
    global $posts, $numpages;
    
    $request_uri = $_SERVER['REQUEST_URI'];
    
    $result = preg_match('%\/(\d)+(\/)?$%', $request_uri, $matches);
    
    $ordinal = $result ? intval($matches[1]) : FALSE;
    
    if(is_numeric($ordinal)) {
    
        // a numbered page was requested: validate it
        // look-ahead: initialises the global $numpages
    
        setup_postdata($posts[0]); // yes, hack
    
        $redirect_to = ($ordinal < 2) ? '/': (($ordinal > $numpages) ? "/$numpages" : FALSE);
    
        if(is_string($redirect_to)) {
    
        // we got us a phantom
        $redirect_url = get_option('home') . preg_replace('%'.$matches[0].'%', $redirect_to, $request_uri);
    
        // if page = 0 or 1, redirect permanently
        if($ordinal < 2) {
            header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
        } else {
            header($_SERVER['SERVER_PROTOCOL'] . ' 302 Found');
        }
    
        header("Location: $redirect_url");
        exit();
    
        }
    }

    Источник решения
    Ответ написан