Next Page link is broken – postfixes extra directory names
-
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 );
}
- The topic ‘Next Page link is broken – postfixes extra directory names’ is closed to new replies.