Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically I want * to pull up*/ (not redirect).

I went into the subdomains section of cPanel and set a wildcard for this domain. It appears to be resolving correctly, ie * is bringing up

I've now made a htaccess file in the public_html directory containing:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+) [NC]
RewriteRule (.*) %2/$1 [L]

The error I'm getting is '500 Internal Server Error', any ideas?

share|improve this question
See:… – Dave Drager Jun 19 '09 at 13:35
Hmm, doesn't really help me unless I know that adding a wildcard in cPanel does all that stuff. – zuk1 Jun 19 '09 at 13:41
up vote 2 down vote accepted

Refer to this StackOverflow question: "Create Subdomains on the Fly With .htaccess"

See answers on the question, specifically this link which has examples which should work in your situation.

There are a couple of issues that the Webmasterworld post addresses, including subdomain recursion since the .htaccess also impacts your subdirectories in your main www root.

The final code is like so:

RewriteBase /

#### URL Rewrite Handler for Subdomains (by Randall Krause) ####

RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.mydomain\.org\.?(:80)?$ [NC] 
RewriteCond %{DOCUMENT_ROOT}/subdomains/%1 -d 
RewriteRule ^(.*) subdomains/%1/$1 [E=SUBDOMAIN:%1,L] 

If you want to see what your above code errors out on (what is creating the 500 error), check your error_log. My guess is that it is causing recursion.

share|improve this answer

I would use mod_vhost_alias. For example:

VirtualDocumentRoot /usr/local/apache/vhosts/%-3+

Would map requests as follows:      =>  /usr/local/apache/vhosts/dom1/  =>  /usr/local/apache/vhosts/foo.dom2/

You can of course tailor the way the mapping works. See the documentation for all the details and more examples.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.