Ugly but working IIS-hack
-
I had the dual problem of:
- Having to install wordpress on a clients bl…y IIS-server without the rewrite-module, leading to pretty urls with the index.php in the path.
- Suddenly having a non-working widget-context
The culprits were two things:
The first problem was i the function to get current url, addition with plus-signs
function get_current_url() { if ($_SERVER['REQUEST_URI'] == '') $uri = $_SERVER['REDIRECT_URL']; else $uri = $_SERVER['REQUEST_URI']; + if(substr($uri, 0, 10) == '/index.php') { + $uri = substr($uri, 10); + } $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$uri : "https://".$_SERVER['SERVER_NAME'].$uri; if (substr($url, -1) == '/') $url = substr($url, 0, -1); return $url; }
Thereby i deleted /index.php from the uri, making it possible to match as usual.
The second problem was in the function to match paths. There was a mismatch because of bad configuration, that fooled the function to use https where there should have been a simple http.
Again additions with plus-signsfunction match_path($path, $patterns) { static $regexps; // get home url; $home_url = get_bloginfo('url'); // add trailing slash if missing if (substr($home_url, -1) !== '/') $home_url = $home_url . '/'; + $home_url_arr = explode("://", $home_url); + $home_url = $home_url_arr[1]; + $path_arr = explode("://", $path); + $path = $path_arr[1]; // Check if user has specified the absolute url // else strip home url and check only REQUEST_URI part if ($path !== $home_url && !strstr($patterns, $_SERVER['SERVER_NAME'])) $path = str_replace($home_url, '', $path); // Remove https:// from the url user has specified if (strstr($patterns, 'https://')) $patterns = str_replace('https://', '', $patterns); // Remove https:// from the current url if (strstr($path, 'https://')) $path = str_replace('https://', '', $path); if (!isset($regexps[$patterns])) { $regexps[$patterns] = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<home\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote($home_url, '/') .'\2'), preg_quote($patterns, '/')) .')$/'; } return preg_match($regexps[$patterns], $path); }
I suppose I should have made a replacement pattern or some such, but exploding on the unique delimiter :// works pretty well, thereby removing https:// and https:// killing the mismatch.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Ugly but working IIS-hack’ is closed to new replies.