Getting friendly URLs to work for WordPress on IIS

Friendly URLs make a site a lot easier for both humans and search engines to understand. For example, this post can be accessed by two URLs, a friendly URL and traditional URL.

The friendly URL:

The traditional URL:

You are probably wondering why such a long URL would be considered friendly; after all who would want to type out all of that? You would be right on that point, but that is not what we mean by ‘friendly’. What makes this URL friendly is that it is made of words, so the URL gives you an idea of the subject matter. So ‘friendly’ = easier to understand.

So what does this have to do with WordPress or IIS?

WordPress is a blog publishing system written in PHP and using a MySQL database. PHP sites are more commonly run on Apache, and that Apache is likely running on a server using the Linux operating system. Apache can run on Windows, and the Windows web server (Internet Information Services or IIS) can be made to serve PHP pages.

Since WordPress is most likely to be run on an Apache server, the developers have made it capable of taking advantage of some of Apache’s features. One of these is mod_rewrite, which can rewrite a URL on the fly, using the URL as a query string and passing it to a php file for interpretation. So you could consider mod_rewrite as being able to process virtual URLs. mod_rewrite gets its configuration information from a file called .htaccess.

When you first setup WordPress on an IIS server it is by default configured to use traditional URLs, which work fine. After a bit of a look around you will find the Permalinks page, which is inside Options in Site Admin. It gives a few examples and allows you to enter your own URL structure. So you enter a structure, such as /index.php/archives/%category%/%postname%/, and test it out. You get a blank page. Perhaps you did something wrong? You try a few combinations, and even the examples give you the same result: a blank page. This is because IIS does not have mod_rewrite, or .htaccess files, and there is an undocumented step that needs to be taken before your beautifully crafted friendly URLs will work. You need to make a change to the php.ini file that is in the root directory of your WordPress installation.

First, if you have a php.ini file already, BACK IT UP. You will need the following two lines added to the file:

cgi.fix_pathinfo = 1
cgi.force_redirect = 0

If you don’t feel like copying and pasting all of that, here’s one I made earlier. Just save it as php.ini and upload to the root of your WordPress installation. Like magic, your friendly URLs will just work.