Forum Moderators: phranque

Message Too Old, No Replies

Document_root

         

DrDoc

7:50 am on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How can I reference DOCUMENT_ROOT in .htaccess?

I want to do something like:
php_value auto_prepend_file "%{DOCUMENT_ROOT}/path/file.php"

Is that possible?

spyder

12:57 pm on Feb 29, 2004 (gmt 0)

10+ Year Member



DrDoc,

my experience:

I was not able to use

[b]%{DOCUMENT_ROOT}[/b]
in my rewrite rules, instead I had to hardcode
[b]/path/to/root/[/b]
, as the two were quite different. I have no idea why
[b]%{DOCUMENT_ROOT}[/b]
(wrong) is different from PHP's
[b]$_SERVER['DOCUMENT_ROOT'][/b]
(correct). And
[b]%{ENV:DOCUMENT_ROOT}[/b]
did not show any value in my case.

Maybe this depends on your webspace / server provider.

For debugging purposes I did something like:

    RewriteRule ^.*$ test.php?%{DOCUMENT_ROOT}¦%{ENV:DOCUMENT_ROOT} [L]

having test.php just spitting out

$_SERVER['QUERY_STRING']
:

    <?php

    echo strtr($_SERVER['QUERY_STRING'], array("¦" => "<p>", "," => "<br>", "; " => "<br>", "%3A" => ":", "%40" => "@"));

    ?>

(the replacements are mainly for other variables to be formatted neatly like

%{HTTP_COOKIE}
etc.)

Maybe someone else has any idea.

Good luck.

DrDoc

6:32 pm on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, after hours of research and testing it seems like you can't use DOCUMENT_ROOT in a path to a file. You can use it for other purposes in an .htaccess file, just not the way I was hoping.

And, that's when I realized I was taking the wrong approach to the problem. Simply setting the PHP include_path to my root directory, and then only use the directory path relative to the root will of course do it :)
I can't believe I didn't think about that before.

php_value include_path .:/whatever/your/document/root/is
php_value auto_prepend_file path/file.php

Thanks for trying, spyder :)

jdMorgan

10:53 pm on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc,

I've used the following code on several servers with no problems, so I suspect that it *does* depend on your server configuration.


RewriteCond %{QUERY_STRING} ^id=(.+)$
RewriteCond %{DOCUMENT_ROOT}/comm/xyz%1.html -f
RewriteRule ^comm/abc\.html$ /comm/xyz%1.html [L]
RewriteRule ^comm/abc\.html$ - [F]

Jim

DrDoc

11:02 pm on Feb 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use it for other purposes in an .htaccess file, just not the way I was hoping.

RewriteCond %{DOCUMENT_ROOT}/comm/xyz%1.html -f

Yes, it works in a mod_rewrite statement... you just can't use it the way I wanted to use it.