Enabling Pretty Permalinks for WordPress on a Windows Server
Although WordPress is generally associated with LAMP stacks, you can run it on a Windows Server too. But setting up pretty permalinks by URL rewriting is different on Windows and Linux. Here’s how to do it on Windows.
Although WordPress is generally associated with LAMP stacks (Linux – Apache – MySQL – PHP) you can run it on a Windows Server too. My company develops .NET applications and we have a number of Windows Servers so it makes sense to use them to run WordPress. MySQL runs well under Windows, and you also get good built-in support for PHP. But we’ll still use IIS so we have a WIMP stack (Windows – IIS – MySQL – PHP).
Specifically, I’m using a Windows Server 2008 R2 with IIS 7.5. Earlier versions may be different to set up.
When you first install WordPress the URL pointing to the posts are crude, like when I set up WP on coinparade.co.uk:
http://www.coinparade.co.uk/?p=25
The link works OK but I would rather the URL be:
http://www.coinparade.co.uk/the-gold-sovereign
It looks better, gives a description of what it may be about and is easier to read and remember. You also improve SEO as it gives search engines more description of the target content.
This is easy to set up with WordPress, but you need to tell your server that you are going to rewrite the URL. URL rewriting is a bit of a smoke and mirrors trick; we’re not making large internal changes, just making the URL look better for the user. And you don’t have to do much at all to achieve this. There are two stages:
In WordPress Admin, set the Permalinks to Post name.
By doing this we will use the post or page title (by default) as part of the URL. WordPress should ensure that the name is OK to use over the Internet so you don’t have to worry about bad characters in the name.
Set up the URL rewriting
This is where Windows is different from Linux machines. On Linux you would add a .htaccess file, but Windows server doesn’t use that. Windows uses web.config, a file that is very familiar to ASP.NET programmers. The web.config is just a text file that IIS uses to configure your website so it can understand the requirements of your application.
In the root of the folder where your WordPress application is, you need to add a blank text file and rename it to web.config. Note that you may already have a web.config as if you have used the IIS manager to create the site it may have already created one. Edit whichever you have and make it look like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<rewrite>
<rules>
<clear />
<rule name="WP Permalinks" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile"
ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory"
ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php"
appendQueryString="true" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.htm" />
<add value="index.htm" />
<add value="index.html" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
This web.config is actually doing several things, but you can see the rule section clearly. URL case is set to insensitive. The files sections is just the order in which the default document is run (you probably only need index.php).
This is how I’ve done it on my development machine, but on production machines please take advice from your IT department, especially regarding security matters.