About design and nearby

WordPress Pretty Permalinks on IIS

Posted: January 2nd, 2014 | Author: | Filed under: Development, Tips and Tricks | Tags: , , , , , | No Comments »

Once I setup WordPress blog on the client website. It was a large content management system configured as the main site in IIS with a subfolder running WordPress also. The problem I faced was getting permalinks to work (by default WordPress uses web URLs which have question marks; the ability to create a custom URL structure for permalinks is useful from SEO perspective and this feature works like a charm usually.) Unfortunately, my case was a bit different.

The problem:
If I check any settings for the website in subfolder (exept default) in WordPress Administrator Option tab, I got 500 error.

WordPress Pretty Permalinks on IIS

Have to say that to make permalinks work correctly you should ensure that both folders: the root folder (serving the primary site) and the subfolder have an unique web.config file.

My web.config settings were according to ‘Enabling Pretty Permalinks in WordPress’ docs by Microsoft.

Rewrite rule in subfolder’s web.config file:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>  
  3.   <system.webServer>
  4.     <rewrite>
  5.       <clear />
  6.       <rules>
  7.         <remove name="wordpress"/>
  8.         <rule name="Main Rule" stopProcessing="true">
  9.           <match url=".*"/>
  10.           <conditions logicalGrouping="MatchAll">
  11.             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
  12.             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
  13.           </conditions>
  14.           <action type="Rewrite" url="index.php/{R:0}"/>
  15.         </rule>
  16.       </rules>
  17.     </rewrite>
  18.   </system.webServer>
  19. </configuration>

I set ‘clear’ tag to handle configuration inheritance. That didn’t work for me.
I added

  1. <remove name="wordpress"/>

to remove the rewrite rule that was set in the root folder (in my case, it was called ‘wordpress’) – zero result.

The solution:
I wrapped my code in the parent config file with

  1. <location path="." inheritInChildApplications="false">

to prevent settings that are specific to a certain location from being inherited by application that exist in subdirectories.

Rewrite rule in root folder’s web.config file:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3.   <location path="." inheritInChildApplications="false">
  4.     <system.webServer>
  5.       <rewrite>
  6.         <rules>
  7.           <rule name="wordpress" patternSyntax="Wildcard">
  8.             <match url="*"/>
  9.             <conditions>
  10.               <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
  11.               <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
  12.             </conditions>
  13.             <action type="Rewrite" url="index.php"/>
  14.           </rule>
  15.         </rules>
  16.       </rewrite>
  17.     </system.webServer>
  18.   </location>
  19. </configuration>

The last thing solved the issue.

Share Button

Check Related Posts:


Leave a Reply


  • three × = 6

Looking for a Freelance UX & UI designer for your project? I’m ready to jump onboard!

Let's discuss your project now