WebFaction
Community site: login faq

I run a website on Webfaction using Drupal and have added the Boost module. Boost relies on alterations to the .htaccess file, rewriting anonymous web requests to a cache directory to avoid hitting PHP and the database, speeding the site up.

I'd like to use %{DOCUMENT_ROOT} in my .htaccess file, so that the rewrite rules remain portable.

Now my question: I've used PHP to examine the contents of $_SERVER['DOCUMENT_ROOT'] and it shows me exactly what I'd expect on my staging site, but for my real site, it shows:

/home/owlstone/webapps/_

It should be /home/owlstone/webapps/drupal6. I've read the docs about DOCUMENT_ROOT here - but I think that's for changing the value as seen by PHP, not by Apache when it interprets the .htaccess file.

Am I missing something, or do I need to open a ticket and ask Webfaction why the default value of DOCUMENT_ROOT is wrong for my particular application?

All help appreciated, thanks in advance

Richard

asked 18 Dec '13, 10:39

richard_owls...
112
accept rate: 0%

Update: I've discovered that %{ENV:PHP_INI_SCAN_DIR} contains the correct absolute directory path when expanded by Apache, for both my webapps. I'll use this, but it'd be nice to know what's going on with DOCUMENT_ROOT

(18 Dec '13, 10:42) richard_owls...

Instructions for setting your DOCUMENT_ROOT are available in our documentation: Configuring DOCUMENT_ROOT

Hope that helps!

permanent link

answered 18 Dec '13, 17:43

seanf
12.2k31836
accept rate: 37%

Thanks for the quick response. I'm afraid I'm not sure it does help, though. It's not DOCUMENT_ROOT for PHP that I need to change. I think it's DOCUMENT_ROOT as interpreted by Apache, in the .htaccess file that's causing my problem. I understand how I can alter it for PHP (I linked to the same page you did, in my question), but the Boost module works by rewriting requests to avoid using PHP entirely...

If I'm misunderstanding this, please let me know. It seems that in /home/owlstone/webapps/staging, DOCUMENT_ROOT is correctly set by default to the directory itself, whereas in /home/owlstone/webapps/drupal6, that variable is set to /home/owlstone/webapps/_ (I dunno where the underscore has come from). Did I get something wrong when I set up the drupal6 application in the Control Panel maybe?

(20 Dec '13, 04:48) richard_owls...

The underscore is used by our system when you have 2 applications mounted on a domain, it's not clear what the document_root should be set to so we do not make an assumption. In this situation you must set the DOCUMENT_ROOT.

(20 Dec '13, 07:44) timg ♦♦

In case anyone else hits this, I hope this page shows up in your searches. I can't find anywhere that webfaction mention it in their documentation. @timg could you mention this somewhere in the docs maybe?

As @timg has clarified (thank you!), if you have multiple applications mounted on a domain, the value of %{DOCUMENT_ROOT} in your .htaccess file will be expaned to a directory path that ends with an underscore. This value also gets reported by PHP as $_SERVER['DOCUMENT_ROOT'].

The answers and links from seanf and timg will help you fix the problem if you need to use the value of DOCUMENT_ROOT from a PHP app. In my case, I specifically needed to be able to refer to "the current directory" within my .htaccess file, in order to configure Drupal's Boost module.

So, for others who might hit this:

  • I've verified that timg is correct - dropping down to a single application causes DOCUMENT_ROOT to revert to what you'd expect.
  • If you wish to retain multiple apps, use %{ENV:PHP_INI_SCAN_DIR} instead of %{DOCUMENT_ROOT} in your .htaccess, as I mentioned above.
permanent link

answered 03 Jan '14, 04:36

richard_owls...
112
accept rate: 0%

edited 03 Jan '14, 04:37

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×75
×27

question asked: 18 Dec '13, 10:39

question was seen: 5,583 times

last updated: 03 Jan '14, 04:37

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM