Today, I was restoring a backup of a WordPress site I have. Copied all the files into a folder, squirted all the data back into MySQL and set up a separate website in IIS. All was fine, I could browse to the main page www.domain.com/index.php and got the page I expected, but clicking on any of the links gave me a 404 error. A bit of checking uncovered that it was probably down to the pretty links that WordPress was configured to use.

It seems that IIS interprets http://www.domain.com/category/blog-post-title/ as a request to view the folder contents or the default page in that particular folder ( /category/blog-post-title ), when in actual fact WordPress is expecting that URL to be passed to index.php so that it can be parsed and the correct content rendered.

Anyway, this can be solved via a simple IIS Rewrite Rule. To get this working add the following to the web.config file that is in the same folder as all the WordPress files :-

<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 needs to into the <system.webServer> section.

This article has 1 comments

  1. TheNuts Reply

    I’m really impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>