How to set up clean URLs for a Wordpress site in IIS
April 10th, 2008
As promised in the previous post, here’s what you need to do to get clean URLs for WP in IIS.
- Create a new PHP file wp-404-handler.php in the root folder (in case you are not sure, this is the folder that has “wp-admin”, “wp-content”, “wp-includes” sub folders and bunch of other php files ) and copy paste the following code in it.<?php
$qs = $_SERVER['QUERY_STRING'];
$pos = strrpos($qs, ‘://’);
$pos = strpos($qs, ‘/’, $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include(’index.php’);
?> - Open IIS manager – Expand local computer – Expand Web Sites – Right click on your site – Click Properties – Click Custom Errors tab – Select 404. (See image below)

- Click Edit – Set Message Type to “URL” and URL to “/” (See image below)

- Click OK.
- Now login to your WordPress admin control panel. Click Settings and click Permalink (wp-admin/options-permalink.php)
- Select “Custom structure” and set the text to “/%year%/%monthnum%/%day%/%postname%/”
- And you are done! Your site should now have clean URLs like this site does.