Forum Moderators: phranque

Message Too Old, No Replies

Undo Mod_Rewrite Wildcard DNS/VHost Hack

         

kozy

11:58 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



Hello everybody,

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

coopster

12:39 am on Apr 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, 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.

kozy

1:01 am on Apr 6, 2006 (gmt 0)

10+ Year Member



Wait a moment here, I think I finally got it...

kozy

12:29 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



mm, I didn't. Concerning the above message, I don't have acces to httpd.conf so thats no use.

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

kozy

12:57 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



By the way, I don't have access to my errorlogs :S

jdMorgan

3:43 pm on Apr 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are apparently problems at several levels here.

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]

it is impossible to get 'above' the Web root directory (which I presume in this case to be "www". To allow such an access mechanism would be a major security problem.

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

kozy

4:13 pm on Apr 6, 2006 (gmt 0)

10+ Year Member



well, my root directory is home/

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)

jdMorgan

7:19 pm on Apr 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Be careful, though... We are looking for the "Web root" not the server root. And as it stands now, the Web roots may differ depending on what subdomain is requested. If /home/ is your Web root, then /home/ should not appear in your URLs or in your RewriteRules. And it will be impossible to rewrite to any directory above /home/.

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

kozy

11:45 am on Apr 7, 2006 (gmt 0)

10+ Year Member



ok so I should use /www/ but it still gives me an Internal Server Error. Could it be because it comes to the webroot searching for a directory?

jdMorgan

1:34 pm on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without access to error logs, all I can advise is to try moving a simple .htaccess test file from low-level directories up to the highest-level directory where it will still work (not cause a 500-Server Error). That may reveal some important information related to this problem.

A simple rule like


RewriteRule ^foo\.html$ / [L]

would be best.

Then request "foo.html" from that directory, and it should rewrite to your home page.

Flush your browser cache after each test.

Jim