Hi Raluca,
Here's what I did:
1) Had my hosting company set up "wildcard DNS". That makes their
nameserver accept anything.domain.com as a request for something
in the namespace of domain.com
2) Edited the httpd.conf file. You may be able to get your host to do
this for you since you can't do it yourself.
Here's what I put into the httpd.conf file:
<VirtualHost 11.22.33.44>
DocumentRoot "/home/owner/domain.com/htdocs"
ServerName
www.domain.com
ScriptAlias /cgi-bin/ /home/owner/domain.com/cgi-bin/
LogLevel emerg
CustomLog /home/owner/domain.com/logs/access_log "combined"
ErrorLog /home/owner/domain.com/logs/error_log
ServerAlias *.domain.com
LimitRequestBody 15360000
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$
RewriteCond ^www\.domain\.com/folder/%2 !-d
RewriteRule ^(.*)$ /folder/%2/$1 [L]
</VirtualHost>
Since your web site is most likely on a shared host, there's probably
a <VirtualHost 11.22.33.44> ... </VirtualHost> block in httpd.conf file.
In the first line is the IP address. There are probably several sites
on the same IP address, so the lines:
DocumentRoot "/home/owner/domain.com/htdocs"
ServerName
www.domain.com
ScriptAlias /cgi-bin/ /home/owner/domain.com/cgi-bin/
These Unix/Linux paths may be different on your server!
tell the system where your /htdocs (or /www or /public_html) folder
is located in that computer's file system. The third of those 3 lines
helps it find CGI scripts for your site.
This line:
ServerAlias *.domain.com
means that anything.domain.com is a potentially valid address,
as well as that any path below it in the file system tree could point
to a real file.
This line:
Options +FollowSymLinks
might not matter but it can't really hurt.
This line:
RewriteEngine on
activates the rewiting function for this site even if no other site on
'the server is using it (in most cases... but YMMV)
Now for the magic part. I want ot make sure that any request for a
page, etc. in the main domain is ignored by the rewite engine, so
this line:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
takes care of it. Only requests that DON't start with:
www.domain.com (not case sensitive) can be rewritten.
The next condition is that any request that starts with:
subdomain.domain.com (with or without "www.") can be rewritten.
This line does the trick:
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com$
In the "regular expression", this part-> ([^\.]+) is the subdomain.
Because it's in parentheses, it will be "remembered" as %1 That will
important later in this block.
Next I wanted to figure out is a subdomain matched up with a real
directory on the server. So this line:
RewriteCond ^www\.domain\.com/folder/%2 !-d
says "If there's no such folder, ignore the request". The !-d is the
important thing here. It means "is not a directory".
Now for the rewrite rule itself:
RewriteRule ^(.*)$ /folder/%2/$1 [L]
It says "map anything that satified all the conditions to a file in
the subdirectory /folder or in any directory below it. So if a user
asks for: subdomain.domain.com/archives/item125.html, the server
will find it here: /folder/archives/item125.html
In my case, all files that "belong" to subdomains are below /folder.
If the possible paths to files "owned" by the subdomains included
stuff that was directly below the /htdocs (or /www or /public_html)
directories, the last two lines would look more like this:
RewriteCond ^www\.domain\.com/%1 !-d
RewriteRule ^(.*)$ /%1/$1 [L]
Try editing these lines to match your system and getting tech support
at your hosting company to add them to httpd.conf. If they won't do
it for you, then I guess you're stuck with using .htaccess files in
every directory that "belongs" to a subdomain. That's going to mean
being very careful about how you edit the regular expressions. And
it may or may not work at all.
kaspar