Forum Moderators: phranque
My host has a dns line like this: *.domain.tld
this is my directory structure
home/www/
home/_ --> home/www
home/this_dir_is_automatically_a_subdomain/
home/every_dir_here_is_automatically_a_subdomain_too/
I want the wildcard dns functionality but I dont want it to search for a corresponding directory. I just want to direct all my subdomains to one directory.
I understand that you will not write code for me but I want to know if it this is possible at all.
If it is, a hint in the right direction will offcourse be very much appreciated. I'm searching a very long time allready...
Also see my post here [webmasterworld.com...]
Thank you, Kozy
If you only have one <VirtualHost> [httpd.apache.org] container and in that container you have your subdomains defined with a ServerName [httpd.apache.org] wildcard you could serve all your subdomains from that same directory.
I have this in my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.myhost\.tld
RewriteRule .* /home/myaccount/www/ [L]
There is no other .htaccess lying around.
But like this I always get an Internal Server Error
First, mod_rewrite code cannot 'reach' above the directory in which it is executed. So in this code
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.myhost\.tld
RewriteRule .* /home/myaccount/www/ [L]
Also, because this is what you apparently think needs to be done, it's likely that you'll need to use your 'Control Panel' instead of or in addition to mod_rewrite. A requirement for a mod_rewrite solution is that the mod_rewrite code must exist in a directory that is always traversed to reach any resource that that code is expected to affect. So if your control panel has configured your virtual server to point each subdomain to a separate subdirectory, then mod_rewrite in .htaccess will only work on an individual subdomain-subdirectory basis. And the evidence suggests that your server is configured in this way right now.
Assuming I guessed correctly about your directory hierarchy, you'd want to point all subdomains to /home/myaccount/ or /home/myaccount/all_subs/, and then use mod_rewrite in that directory to 'sort them out' and rewrite or redirect them as desired.
BTW, a 'Control Panel' is nothing more than a script which modifies the httpd.conf or conf.d file for your virtual server, and does so in a 'safe' and pre-tested way. As such, it is limited in capability, and often produces non-optimized configuration code.
Jim
at first I also thought it was home/www/ but it isnt and I found out by putting in an .htaccess file and deliberatly making a mistake which resulted in al my domains having an Internal Server Error.
So it should be possible?
My host has its own 'control panel' which laks function for changing my vhost configuration and the tell me to figure out myself by using rewrite :s
Do you understand what kind of configuration they use? Also note the '_- symlink to www/ this is used for transparantly serving mydomain.tld with home/www/. I.e. if I remove the '_' symlink and request mydomain.tld the apache errorlog says could not find '_' (don't know if the last info is of any use)
(In case youre wondering I used to have the apache logs available but not anymore)
The first thing to do is to get all subdomains pointed to the same Web root filesystem directory. That done, any request for any subdomain will run code in that Web root directory. After that, the rest is easy.
Jim
A simple rule like
RewriteRule ^foo\.html$ / [L]
Then request "foo.html" from that directory, and it should rewrite to your home page.
Flush your browser cache after each test.
Jim