WordPress and Subdomains

| August 22, 2010

Wanted to post something here that would be visible to others having the same problem, because it took me a lot of hours to diagnose and fix it.

Background:

For several years, I have had a hosting account with GoDaddy, one of the largest hosting providers out there. I have a Windows hosting plan (as opposed to Linux) because I have some ASP pages that go against an Access database (perhaps someday I’ll convert them to PHP & MySql). I host this specific site (geefamily.net) plus one other site with its own domain name. This secondary site resides as a subdomain inside its own folder.

I use WordPress as the framework for both of these sites, and WordPress will work just fine on a Windows server as long as your host has the right set-up (IIS 7, FastCGI, PHP5). And, in fact, my two domains have been working fine for for the several months (and, in the case of the geefamily site, over a year in WordPress). For my secondary site, I had implemented “pretty permalinks,” so instead of having the URL read something like
http://www.example.com/?p=123
I can use something like:
http://www.example.com/about

The Problem

I started noticing a couple of days ago that I was getting a 500 – Internal Server Error on the secondary site (the one located as a subdomain). No real error messages that I could diagnose, so I e-mailed GoDaddy support, and I got a really nice suggestion for displaying detailed error messages. Basically, I had to go into the web.config file and make the following modifications:

  • Add the httpErrors and asp lines below to the <system.webServer> section:

    <system.webServer>
        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>
        <rewrite>
          <rules>
          ...
    </system.webServer>

  • If not already present, add the section <system.web> as a new section in <configuration> with the following settings for customErrors and compilation:

      <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
      </system.web>

After making the changes to my web.config file, I could now see the exact error, which read:
Cannot add duplicate collection entry of type ‘rule’ with unique key attribute ‘name’ set to ‘wordpress’

OK, progress, but what duplicate wordpress rule was it talking about? When I looked at web.config, I could only see one rule defined for wordpress. Thus began a series of Googling and experimentation, including deleting web.config altogether and rolling back WordPress from 3.0.1 to 2.9.2, none or which worked (WordPress will automatically create web.config if you have custom permalinks turned on).

The Solution

It finally dawned on me that somehow my subdomain was trying to inherit the settings from my primary domain’s web.config file (my primary domain resides in the root), causing the duplicate rule error. I managed to find a solution from someone having a problem with a similar Drupal setup (i.e., a secondary domain in a folder under a primary domain). The fix is to modify the web.config file in the root domain by adding this line after the <configuration> tag:

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

and then this line before the closing </configuration> tag:

</location>

So your web.config file for the root domain should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
...

</location>
</configuration>

This will prevent your subdomain from inheriting the web.config file from your root folder and giving you the duplicate rules error.

Hope this helps. I’m thinking if I implemented the multi-site feature on WordPress 3.x, I might have not received this error (maybe a second web.config file wouldn’t be written?), but I started out with two separate WordPress 2.x installations, so I upgraded each individually to WP 3.0.

9 thoughts on “WordPress and Subdomains

  1. Andrew D.

    I’m not using a sub-domain but I’m using ONE hosting account \root has WordPress 2.9.1 on DomainA and \root\subfolder is a second separate domain (DomainB) with a separate install of WordPress 3.3.2.

    Would your solution also fix my issue?

    1. Ron Post author

      Would your solution also fix my issue?

      If you’re hosted on a Windows server, Andrew, I think it would. I would first try enabling the diagnostics by making the changes to web.config under The Problem section above. I think you just need to do it in the web.config file that’s in the subfolder (make sure you create a backup copy of the original in case you muck it up). Then try to access your site under the subfolder and see if you get the duplicate collection entry error. If so, then proceed with the rest of the above solution. Good luck.

  2. E Miles

    Thanks for this guide. Was having this problem and the godaddy support team was no help.
    This fixed my issues!

  3. Alex

    I’ve been living with this problem for so long! Thanks a million for this 😀

  4. Don B.

    I am so glad I was able to find this. I just like you and E Miles was having issues with godaddy’s hosting service and this worked perfectly. I added the:

    to my root domain’s web.config then proceeded with my subdomain’s web.config with the details… BOOM!!! Good to go. Thanks for posting this Ron,

    Don B.

  5. Bcalla

    Holy moly, this just saved me a ton of time. Thanks for the troubleshoot.

    Awesome-sauce!

Comments are closed.