defsounds

http://revisedagain.com/wp-content/themes/r

WordPress Permalinks With IIS 7 and Web.Config, Removing index.php

Posted on August 16th, 2011 WordPress Permalinks With IIS 7 and Web.Config, Removing index.php

From reading previous posts, it may seem like alot of my work has to do with pretty URLS. What can I say,  I like pretty things. This time around I came around having to set up permalinks on an IIS Windows server. Prior to this little journey of frustration–I had never dealt with a web.config file. Until as of late, I’ve only had experience with Apache..cause, why in the world would anyone run a windows server for a web application?

Moving on–Wordpress has made setting up Permalinks extremely easy–unless you’re running wordpress on a Windows server. To get this to work, you should have Fast CGI installed as well as IIS’s URL_Rewrite module.

First we’re going to set up Permalinks in wordpress. Under settings, click Permalinks and select the format you’d like. I’ll be using the following:

  
  1. /%year%/%monthnum%/%postname%/

Once you’ve done this, click Save Changes.

This works well, however, the URL isn’t so pretty. If you notice, all the URLs have index.php appended to them–which sucks.

This is where the URL_Rewrite mod comes in. Once you have the mod installed, create a web.config file with the following rules:

  
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <system.webServer>
  4.  <defaultDocument>
  5.      <!-- Set the default document -->
  6.       <files>
  7.         <remove value="index.php" />
  8.         <add value="index.php" />
  9.       </files>
  10.     </defaultDocument>
  11.         <httpErrors errorMode="Detailed"/>
  12.     <rewrite>
  13.         <rules>
  14.             <rule name="wordpress" patternSyntax="Wildcard">
  15.                 <match url="*" />
  16.                     <conditions>
  17.                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  18.                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  19.                     </conditions>
  20.                 <action type="Rewrite" url="index.php" />
  21.             </rule>
  22.         </rules>
  23.     </rewrite>
  24. </system.webServer>
  25. </configuration>

Note: Make sure there’s no white space at the beginning or end of the file. It’ll spit out errors.

The first part of the config file..Remove Index.php:

  
  1. <defaultDocument>
  2.      <!-- Set the default document -->
  3.       <files>
  4.         <remove value="index.php" />
  5.         <add value="index.php" />
  6.       </files>
  7.     </defaultDocument>

This pretty much tells the application to function without the awful “index.php” appended in the URL.

The second part let’s troubleshoot:

  
  1. <httpErrors errorMode="Detailed"/>

Tells the app to show us exactly whats going on when an error happens, you can leave this out. I use it for troubleshooting purposes.

And now the WordPress Rule, this lets you use whatever URL structure you’d like.

  
  1. <rewrite>
  2.         <rules>
  3.             <rule name="wordpress" patternSyntax="Wildcard">
  4.                 <match url="*" />
  5.                     <conditions>
  6.                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  7.                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  8.                     </conditions>
  9.                 <action type="Rewrite" url="index.php" />
  10.             </rule>
  11.         </rules>
  12.     </rewrite>

Place this web.config file on the root of your wordpress installation and it should function the same as an .htaccess file in Apache.

And there you have it. Next up–> WordPress Multisite set up rules.

2 Comments for WordPress Permalinks With IIS 7 and Web.Config, Removing index.php



Robin

My server is currently on IIS7 by a hosting provider on a shared windows hosting. How do I install IIS and URL_Rewrite as I only have login to plesk control panel which doesn’t have much.

Please help thanks

admin

Your host may have to set that up for you. Try contacting them.



Leave a comment