0

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.

0

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.