Fixing Broken Paging Links in WordPress Running on Windows
Note:Updated instructions for WordPress 3.0 can be found here.
I periodically review Google Analytics and Google Webmaster Tools for a couple of different sites I that manage, and I noticed that there were several pages on my blog with broken links. It turns out that on any page with a link to “Recent Posts” or “Older Posts” the links were broken because an extra index.php was added.
So, instead of links to
/index.php/category/categoryname/page/2
is was seeing
/index.php/Index.php/category/categoryname/page/2
By adding the following line to the clean_url() method in the /wp-includes/formatting.php file in the folder where WordPress is installed the correct links will be created. Make sure you add the link before any if statements.
$url = str_replace('index.php/Index.php','index.php',$url);
Now, my clean_url() method looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | function clean_url( $url, $protocols = null, $context = 'display' ) { $original_url = $url; if ('' == $url) return $url; //Added line to Fix Broken Paging Link Problem $url = str_replace('index.php/Index.php','index.php',$url); $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url); $strip = array('%0d', '%0a', '%0D', '%0A'); $url = _deep_replace($strip, $url); $url = str_replace(';//', '://', $url); /* If the URL doesn't appear to contain a scheme, we * presume it needs http:// appended (unless a relative * link starting with / or a php file). */ if ( strpos($url, ':') === false && substr( $url, 0, 1 ) != '/' && substr( $url, 0, 1 ) != '#' && !preg_match('/^[a-z0-9-]+?\.php/i', $url) ) $url = 'http://' . $url; // Replace ampersands and single quotes only when displaying. if ( 'display' == $context ) { $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&$1', $url); $url = str_replace( "'", ''', $url ); } if ( !is_array($protocols) ) $protocols = array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'); if ( wp_kses_bad_protocol( $url, $protocols ) != $url ) return ''; return apply_filters('clean_url', $url, $original_url, $context); } |
I found the solution here from a commenter name Donbert.
Updated:
I just upgraded to WordPress 2.9.1, so I am not sure this change will get overwritten next time I upgrade.. Upgrading to WordPress 2.9.2 overwrote this change. So it looks like this will have to be done every time WordPress is upgraded.




