• On my site when you click on the next page link, you get something like this…

    https:///domain.com/path/path/index.php?paged=2

    With a duplicate directory path in it.

    In other words the black magic in get_pagenum_link of the /wp-includes/template-functions-links is buggy.

    It’s really amazing how this function tries to derive the proper URL by inspection, but it doesn’t work in my case and I find the code unfathomable.

    My wordpress site is https://cefn.com/curiosity/

    The domain is virtually hosted by using mod_rewrite to transparently redirect cefn.com requests to a subdirectory called cefn.com. This may explain why the REQUEST_URI call in this function doesn’t work as expected.

    However, I’m guessing that this black magic will break for anyone who uses mod_rewrite in the place of virtual hosting, and hence the REQUEST_URI is unexpectedly different from the actual filesystem location, or something.

    I can’t use virtual hosting as I don’t have these admin rights on the server.

    Everything else seems to work OK, it’s just this black magic code which gets confused.


    .htaccess>>>>>>>>

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /

    # Remove www
    RewriteCond %{HTTP_HOST} www.(.*)
    RewriteRule ^(.*)$ https://%1/$1 [R=permanent,L]

    #Redirect requests for cefn.com host to its own sub-directory
    RewriteCond %{HTTP_HOST} (www.)?cefn.com
    RewriteCond %{REQUEST_URI} !/cefn.com/.*
    RewriteRule ^(.*)$ /cefn.com/$1

    #Redirect requests for everyaction.com host to its own sub-directory
    RewriteCond %{HTTP_HOST} (www.)?everyaction.com
    RewriteCond %{REQUEST_URI} !/everyaction.com/
    RewriteRule ^(.*)$ /everyaction.com/$1


    get_pagenum_link black magic >>>>>>

    function get_pagenum_link($pagenum = 1) {
    global $wp_rewrite;

    $qstr = $_SERVER['REQUEST_URI'];

    $page_querystring = "paged";
    $page_modstring = "page/";
    $page_modregex = "page/?";
    $permalink = 0;

    $home_root = parse_url(get_settings('home'));
    $home_root = $home_root['path'];
    $home_root = trailingslashit($home_root);
    $qstr = preg_replace('|^'. $home_root . '|', '', $qstr);
    $qstr = preg_replace('|^/+|', '', $qstr);

    $index = $_SERVER['PHP_SELF'];
    $index = preg_replace('|^'. $home_root . '|', '', $index);
    $index = preg_replace('|^/+|', '', $index);

    // if we already have a QUERY style page string
    if( stristr( $qstr, $page_querystring ) ) {
    $replacement = "$page_querystring=$pagenum";
    $qstr = preg_replace("/".$page_querystring."[^d]+d+/", $replacement, $qstr);
    // if we already have a mod_rewrite style page string
    } elseif ( preg_match( '|'.$page_modregex.'d+|', $qstr ) ){
    $permalink = 1;
    $qstr = preg_replace('|'.$page_modregex.'d+|',"$page_modstring$pagenum",$qstr);

    // if we don't have a page string at all ...
    // lets see what sort of URL we have...
    } else {
    // we need to know the way queries are being written
    // if there's a querystring_start (a "?" usually), it's definitely not mod_rewritten
    if ( stristr( $qstr, '?' ) ){
    // so append the query string (using &, since we already have ?)
    $qstr .= '&' . $page_querystring . '=' . $pagenum;
    // otherwise, it could be rewritten, OR just the default index ...
    } elseif( '' != get_settings('permalink_structure') && ! is_admin()) {
    $permalink = 1;
    $index = $wp_rewrite->index;
    // If it's not a path info permalink structure, trim the index.
    if (! $wp_rewrite->using_index_permalinks()) {
    $qstr = preg_replace("#/*" . $index . "/*#", '/', $qstr);
    } else {
    // If using path info style permalinks, make sure the index is in
    // the URI.
    if (strpos($qstr, $index) === false) {
    $qstr = '/' . $index . $qstr;
    }
    }

    $qstr = trailingslashit($qstr) . $page_modstring . $pagenum;
    } else {
    $qstr = $index . '?' . $page_querystring . '=' . $pagenum;
    }
    }

    $qstr = preg_replace('|^/+|', '', $qstr);
    if ($permalink) $qstr = trailingslashit($qstr);
    return preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_settings('home') ) . $qstr );
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter cefn

    (@cefn)

    I think maybe my question in this post was unclear.

    How do I make the nextpage link actually work OK? Hacks are fine. Currently it just creates a broken link.

    Thread Starter cefn

    (@cefn)

    Anyone?

    Thread Starter cefn

    (@cefn)

    OK so given up on getting any pointers on this request – my fix, to change the number of posts shown on the front page to a very large number, so they are all on the front page and no next link is needed. Nasty hack.

    juberx

    (@juberx)

    Hi all,
    I’ve got the same problem here… Unfortunately, I can’t find any solution to this problem… had checked out other similar posts… but none solved my problem…

    Thread Starter cefn

    (@cefn)

    Found a fix. Given that I’m rewriting URLs anyway in .htaccess, I can rewrite the broken URLs to workaround this bug.

    Added the following to my top level .htaccess file (in /var/www/html on my host).

    >>>>>>>

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /

    #Catch mistaken rewrite rule https://www.ads-software.com/support/topic/44224
    RewriteCond %{HTTP_HOST} (www\.)?everyaction\.com
    RewriteCond %{REQUEST_URI} /(.*)\.com/(.*)
    RewriteRule ^(.*)$ https://%1.com/%2 [R=permanent,L]

    <<<<<<<<

    Means I can’t have any requests for top level directories called anything.com, since they get rewritten to the domain anything.com, such as https://everyaction.com/google.com/search?q=cefn rewrites to https://www.google.com/search?q=cefn

    This is also a problem with the mediawiki engine which I’ve just set up on my domain too. Finally got round to fixing it, so should be able to get back to proper paging on my wordpress site.

    I FINALLY FIGURED IT OUT!!!

    I was killing myself on how to figure this out. I went into Admin, Options, Permalinks and changed the default permalink structure to the one that displays date and post name and it fixed it. I hope it’s not just a temporary fix but it work. Hope that helps.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Next Page link is broken – postfixes extra directory names’ is closed to new replies.