Pretty Permalinks for Multiple Wordpress blogs in sub folders on Windows Hosting with IIS

By webmaster | 09th June 2008 | 2 min read
We recently had a customer who had Windows Hosting with IIS and she had two WordPress blogs hosted on two subdirectories on the same hosting space. Windows hosting should be the last thing that should come to your mind when you want to do WordPress hosting as it will never come close to LAMP (Linux, Apache, MySQL, PHP) functionalities. Now the problem was that she could not set up Permalinks on both blogs. There was an already published solution on how to setup Permalinks in Wordpress on IIS but we had to tweak that a little to get it working in this scenario. The original solution involved the use ofcustom 404 files to handle Permalinks. Since permalinks are not actual pages they will always trigger a 404 error on an IIS server. Now by assigning our own php file to handle this error we can easily parse the URL requested and pass it on to index.php to simulate url-rewrites.

The solution presented in the above site allowed for a single wordpress installation. Here we had two wordpress installations in two sub directories. The solution was to process the request and identify the installation corresponding to which the request was made based on the sub-folder name. Once this was done all we had to do was change directories (for the case where it was needed) and then include the corresponding index.php. We had to chdir because otherwise the working directory would have been the directory where the 404 handler file is located and this could only work for a single installation.

The code used is given below. Copy this and modify for your needs when you have multiple wordpress installations under a domain in IIS and you want Pretty Permalinks for all of them
<?php
$_SERVER['REQUEST_URI'] = substr($_SERVER['QUERY_STRING'], strpos($_SERVER['QUERY_STRING'], ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
if(stristr($_SERVER['QUERY_STRING'], '/blog/'))
  include('index.php');
elseif (stristr($_SERVER['QUERY_STRING'], '/books/'))
{
  chdir('../books/');
  include('../books/index.php');
}
else
  header("location:http://4sometime.com/blog");
If you have questions or problems, use the form given below and we can try to help you. Ideally you should be looking for Linux Hosting Plans when you are looking at Wordpress as your blogging engine. You can also take a look at our competitively priced Linux Hosting Plans