WordPress Breaks Subdomains

Is your subdomain or even different domain is being affected by the WordPress installation in your primary domain? The problem might be in the .htaccess file of your primary domain.

For example, lets say you have a WordPress website or blog as your primary site and any number of websites in folders below that. If someone types in a bad URL for one of your alternate domains, the request gets routed to the /index.php, even if it doesn't exist in the alternate domains. This is especially problematic for 404 errors which may not be handled by the /index.php if it does exist. As a result, your web server would likely go into a redirection loop resulting in an error message similar to:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@yourdomain.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

This happens because WordPress has in essence highjacked the display of all web pages on Web Hosting service using the .htaccess file. Since Apache .htaccess files are inherited in sub-folders, it becomes a problem for all non-WordPress sites. Unfortunately if you remove the .htaccess file, the 404 pages work for the other sites, but it breaks some or all of your WordPress installation.

The good news is that there are at least a couple of solutions.

Solution #1: Conditional Redirection

The first solution is to resolve the issue at the source. By making the redirection conditional, we can essentially tell .htaccess not to redirect other domains in the first place. Here are the lines that WordPress adds to .htaccess when you first install it:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{http_host} ^(www\.)?YourDomain\.com$ [nc]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

The problem is caused by the three lines below the red line which are actually all one rule which tells Apache that, if the request is not for a real file or a real directory, reroute the request to index.php. By inserting the line in red, we are adding a condition make it only applicable to a specific domain. Note: Be sure to change YourDomain and the .com to your specific domain. Do not remove the slash (\) but do replace the www if your domain starts with something like blog instead. For example, blog.YourDomain.com or members.YourDomain.com.

Solution #2: RewriteEngine Off

The second solution isn't quite as elegant as the first solution because it requires that you manually maintain .htaccess files for each of your alternate sites and to remember to do this each time you create a new one.

Simply create a .htaccess file in the root of each of your alternate sites and add one line:

RewriteEngine Off

Besides forgetting to add this line each time you create a new non-WordPress site, you could also run into problems is if your alternate site does actually use the RewriteEngine.

One way around this is to create each of your sites in a sub-folder of a single folder called Websites, for example, and then place this .htaccess file into that folder so that it would affect all of the sites in its sub-folders:

Root of Primary Site
+-- Websites       <--- Put the single line .htaccess file in this folder.
+-- Root of Website 2
+-- Root of Website 3
+-- Root of Website 4
+-- etc.


Leave a Reply

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