Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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

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

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

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

share|improve this question
    
See: stackoverflow.com/questions/586129/… –  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
add comment

2 Answers 2

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 %{ENV:REDIRECT_SUBDOMAIN} ="" 
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] 
RewriteRule ^ - [E=SUBDOMAIN:%{ENV:REDIRECT_SUBDOMAIN},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
add comment

I would use mod_vhost_alias. For example:

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

Would map requests as follows:

  http://dom1.example.com/      =>  /usr/local/apache/vhosts/dom1/
  http://foo.dom2.example.com/  =>  /usr/local/apache/vhosts/foo.dom2/
  etc...

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

share|improve this answer
add comment

Your Answer

 
discard

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.