This walkthrough describes how to enable “Friendly Permalinks” for blog posts in the WordPress blog engine that is installed on IIS 7 and above. Typically, without URL rewriting functionality on a Web server, WordPress users must use “Almost Friendly” URLs, for example, http://sirisgraphics.com/index.php/yyyy/mm/dd/post-name/. By using the URL Rewrite module, you can use “Friendly Permalinks,” for example, http://sirisgraphics.com/post-name/, for WordPress blogs that are hosted on IIS.

Prerequisites

This walkthrough requires the following prerequisites:

  1. IIS 7 or above with FastCGI and PHP installed*
  2. WordPress installed**
  3. URL Rewrite installed

 

* If you need to install PHP, follow the instructions in this article on IIS.net.
** If you need to install WordPress, follow the instructions in this article or use the instructions from the official WordPress site.

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 that is located within the same subdirectory where the WordPress files are.

 

Enabling Friendly Permalinks in WordPress

Use the following instructions to create friendly permalinks for your blog posts.

To enable Friendly permalinks in Word Press:

  • Log on to WordPress with Administrator user rights.
  • In WordPress, click the Permalinks option under Settings. This will take you to the page where you can customize how WordPress generates permalinks for blog posts.
  • On the Permalinks page, select one of the Predefined options, or define a custom structure in the Custom structure text box. You can find more details on the custom structure tags on this page
  • Click on Save Changes.

image

All the blog post links will have URLs that follow the format that 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 the server to rewrite requests that have “friendly permalinks” to an Index.php file. In the next section, you will create a rule that will provide this capability.

Creating a Rewrite Rule

Open the Web.config file that is located in the same directory where the 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 will try to match any requested URL. If the URL does not correspond to a file or a folder on the file system, it will rewrite the URL to the Index.php file. 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 this rule.

Summary

In this walkthrough you learned how to use the URL Rewrite module to enable “friendly 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, a feature that enables user-friendly and search engine-friendly URLs.