homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

A domain with wildcard subdomains and a pointed subdomain in cpanel.
...gives 500 internal server error for any subdir of the pointed subdomain

 9:22 am on Apr 19, 2010 (gmt 0)

On my site, I've got Wordpress in www.mydomain.co.uk, I've got a search engine on find.mydomain.co.uk, and I've got subusers on a wildcard with a script in a subdirectory to work out what to serve, based on the subdomain.

In cpanel, I have, for the subdomain redirect:
*.mydomain.co.uk /mydomain
find.mydomain.co.uk /mydomain/find

in htaccess of the site http document root, I have

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

# END WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][-a-z0-9]+)\.mydomain.co.uk\.co.uk(:80)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co.uk
RewriteRule ^$ subdomainscript/ [L]

It's all good. It all works great.

www.mydomain.co.uk brings up wordpress
user2.mydomain.co.uk brings up user 2's page
user2.mydomain.co.uk/page1 brings up user 2's page1
find.mydomain.co.uk brings up the search engine.

So for, all well and good.

The problem comes with
find.mydomain.co.uk/anydirectory = 500 internal server error.
What's doing my nut in is that find.mydomain.co.uk/test.html will work but find.mydomain.co.uk/directory/test.html gives a 500.

I promise that before coming and asking, I spent my Sunday looking through FAQs and forums. I just can't get my head around mod rewrites and regexp stuff.
I have a feeling that I might need to delete the "find" subdomain redirect in cpanel and do it all in .htaccess as there's the wildcard subdomain.

However, although I can find tutorials on wildcards and wildcards with one subdomain, a day's googling has turned up nothing that works for www, two subdomains AND wildcards for anything which isn't those two subdomains.

Any help would be greatly appreciated.



 1:51 pm on Apr 19, 2010 (gmt 0)

To start, your two rules appear to be in the incorrect order, unless you want requests for your subdomains to be rewritten to WP when they use a URL-path that does not exist in the top-level directory.

Secondly, there is nothing to stop recursion when rewriting to /subdomainscript, and the result will be a rewrite to /subdomainscript, then to /subdomainscript/subdomainscript, then to /subdomainscript/subdomainscript/subdomainscript, etc. until the server gives up and throws a 500-Server error. You need a negative match RewriteCond to exclude requests starting with "/subdomainscript" from being rewritten repeatedly.

There are other problems here related to gross inefficiency of the "factory-issued" WP code. But these are secondary to getting the rules working, so let's address them later.



 7:47 am on Apr 20, 2010 (gmt 0)

Thank you. I've tried them in a different order, and I've found a few other tutorials which suggest things like:

RewriteCond %{HTTP_HOST} !^find\.mydomain\.co.uk
RewriteCond %{REQUEST_URI} !^/(find | assets)

Neither of them work, either.
And I've tried turning rewritelogging on too:

RewriteLog "/home/me/mydomain/rewrite.log"
RewriteLogLevel 2

But apparently I can only do that as root, hence everything going 500.

My head hurts! I think I was destined to never "get" regexp.


 1:43 pm on Apr 20, 2010 (gmt 0)

You need a negative match RewriteCond to exclude requests starting with "/subdomainscript" from being rewritten repeatedly.

You also apparently have a "repeat" of ".co.uk" in one of your RewriteCond patterns, which will stop that rule working.

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co.uk
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9][a-z0-9\-]*[a-z0-9])\.mydomain\.co\.uk\.?(:[0-9]+)?$ [NC]
[b]RewriteCond %{REQUEST_URI} !^/subdomainscript/[/b]
RewriteRule ^$ subdomainscript/ [L]
# BEGIN WordPress
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond ${REQUEST_URI} !\.(gif|jpe?g|png|ico|css|js|pdf|mp3)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

I removed several completely-unnecessary lines, and added several more-useful ones, both to help solve your current problem and to improve server speed/efficiency.

Note that as this code is currently written, whatever script is invoked at filepath "/subdomainscript/" must handle requests for all "find.example.co.uk" URLs and it must retrieve the requested URLs from the server request variables itself, since no variables are passed to it by this rule.

You may want to install and test with a server headers checker like the "Live HTTP Headers" add-on for Firefox, in order to observe the HTTP request/response transactions between your browser and your server; It is possible that the problem involves both your .htaccess code and your script(s).

When you get a 500-Server error, look to your server error log file. It often contains very useful information, and presents the server's and file-handler's views of the error, as opposed to the HTTP view in the server access log. Taken together, both logs are usually very useful.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved