Putting a WordPress Website Live On a Windows IIS Server

July 3rd, 2013 - Posted by Steve Marks to Server Management, Web Development.

A while back I wrote a quick guide on how to put a WordPress site. I still stand by this guide to this day, and still refer back to it myself as a kind of checklist.

Today I came across something different however; Putting a WordPress site live on a Windows IIS Server. It was running PHP and MySQL so that wasn’t a problem, however a couple of additional problems did arise as I explain below…

Default File Type

The first problem was that the Windows server wasn’t looking for a file called ‘index.php‘ by default. It was probably looking for an ‘index.html‘, or an ‘index.asp‘ file instead. Either way, I needed a way to tell the server what the default file was when navigating to the root of the site in a browser.

Allow me to introduce to you the ‘web.config‘ file…

I’ll admit, I didn’t know this before today, but Windows servers don’t acknowledge the .htaccess file we’re so familiar with when working in an Apache environment. As a result, Windows servers have their own similar file simply called ‘web.config‘. Like a .htaccess file, this XML file sits in the relevant directory, and can perform much of the same operations.

Getting back on track, you need to set the default file in this web.config file, and can do so like so:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
        <defaultDocument> 
            <files> 
                <add value="index.php" /> 
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

As you can see above, we are setting ‘index.php‘ to be the default file.

Removing index.php From The Permalink

The next problem I faced was that, because the .htaccess file was being ignored, the mod_rewrite rules weren’t working, and therefore I had to keep ‘index.php’ in the URL for the inner pages to function. Again, this can all be controlled from within our ‘web.config‘ file. Whereas your .htaccess might look something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Our ‘web.config‘ would look like this:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer>
	<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>
    </system.webServer>
</configuration>

Putting It All Together

For convenience I’ve included a copy of the final web.config file I used below that combines the above two snippets of code:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
        <defaultDocument> 
            <files> 
                <add value="index.php" /> 
            </files>
        </defaultDocument>
	<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>
    </system.webServer>
</configuration>
This entry was posted on Wednesday, July 3rd, 2013 at 10:38 am by +Steve Marks and is filed under Server Management, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first