Joe's Quest

URL Rewriting for WordPress in IIS with wp_url_rewriting and patch

There are several ways to use URL rewriting for WordPress in IIS. I’m using wp_url_rewriting for my client. Recently, my client upgraded his WordPress to 3.1 which cause a problem that the page navigation does not work correctly.

Symptom: The page link in a category page, does not contain the category slug. Ex. in http://sampledomain/samplecate/, the page link should be http://sampledomain/samplecate/page/2, but it shows like http://sampledomain/page/2.

This does not happen on my Apache server. So I checked out wp_url_rewriting installation note and I found this:

3). Do a little hack to WordPress file ‘link-template.php’ to make paging works well for categories:(NOTE: You don’t need to do this step if you are using WordPress 2.3.0 or newer)

open file /wp-includes/link-template.php and find the following code:….

From 2.3.0 to 3.0.x, no need to do the hack. Since 3.1.0, it becomes a must again. The original hack does not working. It’s been moved to another file. So do the hack as follows:

open file /wp-includes/functions.php and find following code:

[coolcode lang=”PHP”]
function add_query_arg() {
$ret = ”;
if ( is_array( func_get_arg(0) ) ) {
if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
$uri = $_SERVER[‘REQUEST_URI’];
else
$uri = @func_get_arg( 1 );
} else {
if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
$uri = $_SERVER[‘REQUEST_URI’];
else
$uri = @func_get_arg( 2 );
}

[/coolcode]

Replace the $_SERVER[‘REQUEST_URI’] with $_SERVER[‘PATH_INFO’]

Then wp_url_rewriting will work again.

BTW, after fixing this, I found some updates of ISAPI_Rewrite. The lite version could work well for WordPress. I used that before. I remember there were some limitations for the lite version. Since this article was written on Feb 17th, 2010. I guess it should work fine. If so, this could be a better solution for there’s no hack needed.

 

Leave a Comment

Your email address will not be published. Required fields are bold.