[wp-trac] [WordPress Trac] #48328: IIS 7+ with standard FCGI an URL_REWRITE mangles REQUEST_URI

WordPress Trac noreply at wordpress.org
Wed Oct 16 15:45:55 UTC 2019


#48328: IIS 7+ with standard FCGI an URL_REWRITE mangles REQUEST_URI
----------------------------+-----------------------------
 Reporter:  Andy Schmidt    |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Bootstrap/Load  |    Version:  5.2.3
 Severity:  major           |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 Currently, line 65 in load.php will ONLY recover the original URL, IF IIS
 is still run in the outdated ISAPI mode, and using third-party Rewrites.

 {{{#!php
 <?php
         // Fix for IIS when running with PHP ISAPI
         if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi'
 && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) {

                 // IIS Mod-Rewrite
                 if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) {
 }}}

 However, if IIS is run with the now-standard FASTCGI, and IIS' own URL-
 REWRITE module, then the original URL is NOT recovered from IIS' URL-
 REWRITE module.

 URLs like:
 www.wordpress.site/somepath/ferrari-166-mm-0308m-%e2%8b%9f-
 0328m/?queryparameters=something
 are mangled to:
 www.wordpress.site/somepath/ferrari-166-mm-
 0308m-?-0328m/?queryparameters=something
 resulting in multiple "?" occurrences in the URL.

 The following patch at line 93 in wp-includes/load.php will add
 compatibility with the IIS versions of the past 10 years:

 {{{#!php
 <?php
         }
         // PATCH STARTS HERE *** Fix for IIS when running URL_REWRITE
         elseif ( ( PHP_SAPI == 'cgi-fcgi' ) and isset(
 $_SERVER['IIS_UrlRewriteModule'] ) and isset( $_SERVER['UNENCODED_URL'] )
 ) {
                 $_SERVER['REQUEST_URI'] = $_SERVER['UNENCODED_URL'];    //
 Note: 'HTTP_X_ORIGINAL_URL' actually holds an encoded (non-original)
 version.
         }

         // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something
 ending in php.cgi for all requests
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48328>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list