Forum Moderators: coopster
I was wondering if there was a way using php and/or other common apache modules to change the document root of a subdomain based on login data, collected either by HTTP authentication or just by an HTML form... Without editing apache2.conf or any other server-wide configuration file.
So for instance, joe visits stage.mydomain.com and is presented with a login request. once he logs in, stage.mydomain.com serves him the files contained in /web_designs/joes_site. But when jane logs in she is served the documents in /web_designs/janes_site while accessing the same url.
if it's not in url, then just
include("web_design/".$name."_site/index.php);
However if you want the name to appear in url then redirect
header("Location: web_design/".$name."_site/index.php");
Remember just, that $name cannot contain spaces, apostrophes, quotations, slashes, backslashes, etc.
Best regards
Michal Cibor
I think you are in the right place, if I understand you correctly. Your wording seems a bit incorrect ("change the document root of a subdomain"), but your intention is described well enough to offer a possible solution.
Can we assume you are starting a session since you are authenticating a user? Well, as part of that authentication process, why not store the user's "project directory" as a column in the database? Push that variable into the session and upon successful authenitication, use that to build the url path through out the rest of the session.
[edited by: coopster at 10:30 am (utc) on May 31, 2005]
[edit reason] sorry, no urls (TOS [webmasterworld.com]) [/edit]
The .htaccess file for /stage(which is where stage.mydomain.com is served from):
AuthType Basic
AuthName "myDomain.com Staging Aread"
AuthUserFile "/path/to/passwords"
Require valid-user
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/$ /%{REMOTE_USER}/ [L]
RewriteRule ^(.*)$ /%{REMOTE_USER}/$1 [L]
The above alone, however, creates a loop, and allows one user to access another user's files by pointing their browser to stage.mydomain.com/other_user. So each user directory has to contain the following:
AuthType Basic
AuthName "myDomain.com Staging Area"
AuthUserFile "/path/to/passwords"
Require user <specific_username>
RewriteEngine Off