Ticket #3514 (closed defect: fixed)

Opened 2 years ago

Last modified 11 months ago

IIS fix for get_pagenum_link

Reported by: snakefoot Assigned to: markjaquith
Priority: high Milestone: 2.3
Component: General Version: 2.0
Severity: major Keywords: get_pagenum_link, iis, posts_nav_link, has-patch
Cc:

Description

The posts_nav_link doesn't work in categories, when trying to browse to the second page of a category using "Previous entries", then the link points to:

http://example.com/index.php/page/2/

Instead of pointing to:

http://example.com/index.php/category/page/2/

The fix for me was to modify get_pagenum_link located in template-functions-links.php (Both trunk and branch should get this rather easy fix)

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

	// IIS on Windows fix
	if (!$_SERVER['REQUEST_URI']) $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'];

	$qstr = wp_specialchars($_SERVER['REQUEST_URI']);
...

Attachments

wp-setting.diff (1.4 kB) - added by snakefoot on 07/20/07 21:20:24.
REQUEST_URI patch for IIS

Change History

01/01/07 21:02:59 changed by snakefoot

Just discovered that my IIS didn't react to the IIS test ($_SERVER['REQUEST_URI'] returned "/index.php"). Now changed it according to this advice:

http://www.xoops.org/modules/newbb/viewtopic.php?topic_id=29255

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

	if ( !isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI']==$_SERVER['PHP_SELF'])
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'];

	$qstr = wp_specialchars($_SERVER['REQUEST_URI']);
...

01/05/07 08:47:44 changed by markjaquith

  • milestone changed from 2.0.6 to 2.0.7.

Is this an issue for trunk? If so, it should have a 2.2 milestone.

01/09/07 19:06:29 changed by snakefoot

Unless special updating of REQUEST_URI (if IIS) have been added to 2.1 or 2.2, then it is most likely an issue for the trunk as well (As the get_pagenum_link() is the same in the trunk).

Maybe one should consider creating a global function, which returns the expected URL independent of what PHP/IIS/Apache/Litestep version one is using, and then reuse the function all the locations where REQUEST_URI is used.

Wordpress has different places which tries to handle the REQUEST_URI behavior on IIS, but each implementation is different.

01/09/07 20:00:33 changed by snakefoot

Discovered that wp_settings.php is the only one updating $_SERVER['REQUEST_URI'], so it is probably not a good idea to manipulate the $_SERVER['REQUEST_URI'] in get_pagenum_link, but instead just append PATH_INFO.

01/10/07 13:59:27 changed by markjaquith

  • owner changed from anonymous to markjaquith.
  • status changed from new to assigned.
  • milestone changed from 2.0.7 to 2.2.

03/11/07 01:00:12 changed by rob1n

PATH_INFO is already appended, I think.

04/12/07 18:12:55 changed by foolswisdom

  • milestone changed from 2.2 to 2.3.

05/26/07 01:20:02 changed by snakefoot

With the #3930 solved, the get_pagenum_link() looks much prettier and by changing the following lines it should work with IIS (Notice the str_replace):

     if ( !$wp_rewrite->using_permalinks() ) { 
        $base = trailingslashit( get_bloginfo( 'home' ) ); 

        if ( $pagenum > 1 ) { 
            $result = add_query_arg( 'paged', $pagenum, $base . $request );  
        } else { 
            $result = $base . $request; 
        }
    } else {
        $request = str_replace('index.php/', '', $request);
        $request = str_replace('index.php', '', $request);
        
        $request = preg_replace( '|/?page/(.+)$|', '', $request);

Along with modifying REQUEST_URI in wp_settings.php (Will also make WP-Cache work out of the box):

     // Fix for IIS, which doesn't set REQUEST_URI
     if ( empty( $_SERVER['REQUEST_URI'] ) ) {
        $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];

Must admit that I have only tested this on 2.0 (Exchanged the original get_pagenum_link with the new one in version 2.3). Have tested with permalink using index.php without ISAPI rewrite, and without index.php using ISAPI rewrite, and everything (pages, posts, categories, archives, search, paged) works as they should.

05/26/07 07:10:39 changed by snakefoot

I guess the best solution would be to fix the REQUEST_URI completely. If one could detect that the permalink options is not set to use index.php, then don't include the SCRIPT_NAME in the REQUEST_URI, but just PATH_INFO.

05/26/07 08:15:05 changed by snakefoot

Just made a plugin with the following code and now no modification is needed in the get_pagenum_link() (Still need the modification in wp_settings.php to make WP-Cache work)

function fix_request_uri()
{
	global $wp_rewrite;

	if ($wp_rewrite->using_index_permalinks())
	{
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
	}
	else
	{
		$_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO'];
	}

	// Append the query string if it exists and isn't null
	if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
	{
		$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
	}
}

add_action('init', 'fix_request_uri');

05/31/07 23:08:36 changed by snakefoot

Corrected some bugs in the plugin:

function fix_request_uri()
{
	global $is_IIS;
	global $wp_rewrite;
	if (!$is_IIS)
		return;

	if ($wp_rewrite->using_index_permalinks())
	{
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
	}
	else if ($wp_rewrite->using_permalinks())
	{
		// SCRIPT_NAME includes script-path + script-filename (remove the filename) and append request-path PATH_INFO
		$_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . $_SERVER['PATH_INFO'];
	}
	else
	{
		$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
	}

	// Append the query string if it exists and isn't null
	if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
	{
		$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
	}
}

07/20/07 21:20:24 changed by snakefoot

  • attachment wp-setting.diff added.

REQUEST_URI patch for IIS

07/20/07 21:22:19 changed by snakefoot

  • keywords changed from get_pagenum_link, iis, posts_nav_link to get_pagenum_link, iis, posts_nav_link, has_patch.

Added patch for wp-setting.php which fixes this ticket.

07/20/07 21:54:44 changed by Nazgul

  • keywords changed from get_pagenum_link, iis, posts_nav_link, has_patch to get_pagenum_link, iis, posts_nav_link, has-patch.

08/17/07 03:32:20 changed by markjaquith

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [5889]) Set REQUEST_URI for IIS in more situations. props snakefoot. fixes #3514