Pretty WordPress Permalinks on IIS6

Date May 31, 2010


Most of the blogger started their blog on windows environment with IIS6 without any component installed for URL rewriting like ISAPI_REWRITE. And they don’t know the importance of URL rewriting but when they came to know about rewriting its too late. Following is the solution for those blogger who are willing to rewrite url on their blog.

< ?php
// This is the default file for the site. Usually index.php
$default = 'index.php';

// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a '/' prefix in IIS).
$thisfile = '404-handler.php';

$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;

$qs =& $_SERVER['QUERY_STRING'];
$ru =& $_SERVER['REQUEST_URI'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, '?'), '?');

// Required for WordPress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;

// Fix GET vars
foreach ( $_GET as $var => $val ) {
  if ( substr($var, 0, 3) == '404') {
    if ( strstr($var, '?') ) {
      $newvar = substr($var, strpos($var, '?') + 1);
      $_GET[$newvar] = $val;
    }
    unset($_GET[$var]);
  }
  break;
}
include($default);
?>

Follow the steps.

  1. Create the file wp-404-handler.php in your base WordPress folder.
  2. Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
  3. Go to WordPress Options -> Permalinks in your WordPress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:/%year%/%monthnum%/%postname%.html
  4. Enjoy Pretty URLs

Related Posts

Tags: , ,

PoorFairInterestingGoodExcellent (2 votes, average: 5.00 out of 5)
Loading ... Loading ...

4 Responses to “Pretty WordPress Permalinks on IIS6”

  1. Wasiq said:

    Thank you very much Dean, I have spent a few days researching the best way to get wordrpess pretty permlinks to work on our windows 2003 SBS and your solution is by far the simplest and cleanest way to remove the /index.php from permalinks. In addition to wordrpess permalinks our site has some hard coded PHP url’s which your solution works with also, but if you don’t have the site on the root of your IIS website, ie in a virtual directory, you can use at the front of the Href and all links will work perfectly. Thank you again for spreading sanity across the web.

  2. Fabio said:

    Hi, your solution works perfectly, but i’m having problems to deal with $_Post vars processing. I just can’t get the values passed by a submit form and catching them in the page that’s the target of the form (submit action). By the way, how do I pass paremeters by $_GET with permalinks enabled? For example: http://www.xyz.com/page/?id=2
    Thanks for your attention.

  3. Arlington Heights Dentist said:

    I am going to link my blog to this site. I believe my visitors will uncover it extremely beneficial given the well written subject matter. Thanks

  4. Andrew Joseph said:

    This is actually my very first time right here, really good looking weblog. I discovered a lot of fascinating stuff within your blog especially it is discussion. From all of the comments on your articles, it seems like this is really a extremely well-liked website. Maintain up the great function.

Leave a Reply

 

Most Rated Posts

Subscribe to Technology Tips

Subscribe to Saqib-Ansari via RSS

Or, subscribe via email: