How can I specify auto_prepend_file in my .htaccess file without hard coding the absolute path?

I have a PHP file that I want to execute at the beginning of each request. I specified it in the htaccess file:

php_value auto_prepend_file "alwaysrunthis.php"

The problem is that the value of this directive is executed in the context of the target script, and not in the context of the location of the .htaccess file. Thus, it works if the executable script is executed in the same directory as the preend file, but otherwise not.

I understand that I can use the absolute path, but this is not very portable. Is there any variable I can get in .htaccess to generate an absolute path at runtime?

+3
source share
1 answer

The short answer is no.

Longs, , , .

, $_SERVER['DOCUMENT_ROOT'] var, , , switch/if-else.

__FILE__ var realpath, / "preend", .

-prepend.php
require_once(realpath(__FILE__) . '/prepend.php');

//:
, __FILE__, , preend , , .

+3

All Articles