How To Setup Pretty Premalinks for WordPress on IIS7

If you’re running WordPress on IIS7 like this blog and if you want clean URLs without the “index.php” you can do the following.

Although before you get started you need to make sure you have FastCGI and URL Rewrite Module installed on your IIS7.

If you’re missing one of those things, you can check out these guides:

Once you’ve done that, go to the “Settings” section in your WordPress admin area and click on “Premalinks”:


On that page, choose the “Custom, specify below” option and enter “/%year%/%monthnum%/%postname%/” (or any other format of your choosing) in the “Custom structure” text box.

After you save the settings, you’ll notice that all your blog posts will have their URLs in the format you specified earlier. Although if you try to click on one of them you’ll get a 404 - File Not Found error. Thats because we still haven’t told the server where to go when it gets those requests.

To do so, you’ll have to create a Web.Config file (if you don’t have one already) in the same directory as your WordPress blog. Once you’ve done that, paste the following inside configuration->system.webServer element:

        <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" />
            <action type="Rewrite" url="index.php" />

Click here to download the entire Web.Config file.

That rewrite rule we added above will match 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.

After you’ve saved the Web.config file, fire up any one of the permalinks in your WordPress blog. If everything went as expected, you’ll see the correct content returned by the web server for every permalink.

If you have any questions or comments, please post them below. If you liked this post, you can share it with your followers or follow me on Twitter!