This walkthrough will guide you through how to enable “Pretty Permalinks” for blog posts in the WordPress blog engine installed on IIS 7.0. Typically, without URL rewriting functionality on a Web server, WordPress users have to use “Almost Pretty” URLs (for example, http://contoso.com/index.php/yyyy/mm/dd/post-name/). This was the primary option for users who chose to host WordPress on IIS. Now, with the URL rewrite module available, you can have “Pretty Permalinks” (for example, http://example.com/year/month/day/post-name/) for WordPress blogs hosted on IIS 7.0.
Prerequisites
This walkthrough requires the following prerequisites:
- IIS 7.0 with FastCGI and PHP installed. (If you need to install PHP, follow the instructions in this article.)
- WordPress installed. (Follow the instructions in this article or use the instructions from the official WordPress site.)
- URL rewrite Go Live release installed.
Note that for the purposes of this walkthrough it is assumed that WordPress is installed in a Web site root directory. If WordPress is installed in a subdirectory, then the rewrite rules that are used in this walkthrough should be included in the Web.config file located within the same subdirectory where the WordPress files are.
Enabling pretty permalinks in WordPress
Once WordPress is installed, log on to it as an administrator, and then click the “Options” tab. Then click the “Permalinks” subtab. This will take you to the page where you can customize how WordPress generates permalinks for blog posts.

On this page, choose the “Custom, specify below” option and enter
“/%year%/%monthnum%/%day%/%postname%/” in the “Custom structure” text box.
Click Update Permalink Structure.
Now, you will see that all the blog post links have URLs that follow the format you have specified, but if you click any one of those links the Web server will return a 404 - File Not Found error. This is because Wordpress relies on a URL rewriting capability within a server in order to rewrite requests that have “pretty permalinks” to an Index.php file. In the next section we will create a rule that will provide this capability.
Creating rewrite rule
Create and open Web.config file located in the same directory where WordPress files are installed, and paste the following XML section into the system.webServer element.
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
This rule matches any requested URL and if that URL does not corresponds to a file or a folder on a file system, then it will rewrite the URL to Index.php. At that point, WordPress will determine which content to serve based on the REQUEST_URI server variable that contains the original URL before it was modified by the rule.
Testing the rewrite rule
After the rewrite rule is saved to the Web.config file, open a Web browser and click any one of the permalinks in WordPress blog–you should see the correct content returned by the Web server for every permalink:

Summary
In this walkthrough you have learned how to use the URL rewrite module to enable “pretty permalinks” in the WordPress blog engine. WordPress is just one example of the many popular PHP applications that can take advantage of the URL rewrite module in IIS 7.0, a feature in a system that enables user friendly and search engine friendly URLs.
Related Content
Comments