WordPress permalinks on IIS with a 404 handler – with working querystrings

June 2nd, 2008

I have been using this very useful tip from Keyboard Face to provide WordPress permalinks on IIS without having to worry about an URL rewrite filter. I didn’t even have this option with my previous host, but I’ve stuck with it now I’ve moved this site.

However, as you’ll see in the comments, this doesn’t pass through the querystring parameters (e.g. ?page=2). I’ve added in a section of code to cater for this:

<?php
 
error_reporting(E_NONE);
 
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
 
$qs_vars = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '?')+1);
$qs_vars_arr = explode("&", $qs_vars);
 
unset($_GET);
 
foreach ($qs_vars_arr as $qs_var_entry) {
	$qs_vars_entry_arr = explode("=", $qs_var_entry);
	$_GET[$qs_vars_entry_arr[0]] = $qs_vars_entry_arr[1];
}
 
include('index.php');
 
?>

This may not be the most efficient way to achieve what I want, but it does the job. Comments appreciated so I can optimise.

No Responses to “WordPress permalinks on IIS with a 404 handler – with working querystrings”

  1. There are currently no comments on this entry, want to be the first? Use the form on the right.