Forum Moderators: phranque

Message Too Old, No Replies

Subdomains created "on the fly", outside of document root?

apache subdomains created "on the fly" outside of documentrot

         

basbd

7:59 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



This is a post similar to Subdomains created "on the fly"? [webmasterworld.com] (not allowed to post replies :) )

I was wondering if it was possible to create subdomains "on the fly" using apache Rewrite Rules if the subdomains are outsite of the main site's DocumentRoot.

So, for example, I have a site (user.com) located at:


/home/user/htdocs

and I want to set up subdomains at:

/home/user/subdomains

but have it so when I create a new directory in the subdomains directory, such as "sub/", sub.user.com reads from that directory.

I've tried this, a slightly modified version of the code posted in the post above:


RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^(www\.)?user\.com$ [NC]
RewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC]
RewriteCond %2<->%3 !^(.*)<->\1$ [NC]
RewriteRule ^(.+) /home/user/subdomains/$1 [L]

but obviously that doesn't work because it's trying to redirect to the path "/home/user/subdomains/" on the documentroot ("/home/user/").

Is there any other way to do this?

Thanks,
Jon

[edited by: jdMorgan at 8:14 pm (utc) on July 30, 2005]
[edit reason] Corrected formatting [/edit]

jdMorgan

8:19 pm on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jon,

Welcome to WebmasterWorld!

Assuming that you're using .htaccess, there's no way to go "above" the current document root. To allow this would open sites up to all kinds of security exploits.

So, your choices are to get access to httdp.conf and create your virtual hosts there, or to create the subdomain-subdirectories at or below the current document root.

Jim

basbd

8:23 pm on Jul 30, 2005 (gmt 0)

10+ Year Member



Luckily, I do have access to httpd.conf :). Anyway to do it through httpd.conf?