tags:

views:

257

answers:

2

I know that you cannot simply set DocumentRoot in htaccess but it's all I have access to. Is there a work around? How should I proceed? Or is this the wrong configuration for a setup like this?

I have a dev server where: www.foo.com is mapped to /usr/www/users/foo.

I then have

  • www.foo.com/peter => /usr/www/users/foo/peter
  • www.foo.com/paul => /usr/www/users/foo/paul

How can I set $_SERVER['DOCUMENT_ROOT'] to map to /usr/www/users/foo/peter and /usr/www/users/foo/paul respectively?

Thanks.

+1  A: 

In my experience I've learned never to trust any $_SERVER variables. Instead, I've set the DOC_ROOT myself using a combination of dirname() and a common include file whose location I am certain will never change. A lot of the common frameworks will do something similar in the dispatch or index file which handles ALL requests.

Example Application Folder Structure:

-/usr/www/users/
  -peter/
    -script.php
  -paul/
    -script.php
  -index.php
//index.php

DEFINE('ROOT_PATH', dirname(__FILE__));
echo ROOT_PATH; // /usr/www/users/

More info on php's magic constants like __FILE__

Hope that helps.

Mike B
+1  A: 

DocumentRoot is exactly that: the file system location of the root ( / ) uri for a specific subdomain.

By the time .htaccess is processed, it's already too late to change it. Why? Well... because the .htaccess file you're accessing is in said file system location!

Having said that, you can create a new constant and use $_SERVER['DOCUMENT_ROOT'] as part of it.

R. Bemrose
If I had access to the httpd.conf, would I be able to accomplish what I wanted in the above question?
frio80