I’d like to have an auto_prepend_file executing based on a relative path. For example, I’d like to only set it once in my top level .htaccess file like:
The problem is that when I execute a page in a different directory, Apache tries to load the file as it were in the same directory as the requested file, even though the .htaccess file is NOT. Is there a way to do this? I thought about using DOCUMENT_ROOT but nothing, it’s just seen as “DOCUMENT_ROOT/auto_prepend_file.php”
PHP is behaving in the correct way - as you directed! “./” is the 'nix way to say THIS directory whereas “/” says DocumentRoot. In other words, delete the leading dot and you should be fine.
I’m trying to find a way to set an include path for an entire directory and sub-directories, but using a relative path. For example, put a .htaccess file in the root of the site, set the include_path to something like “./includes/” and then have every page make use of that setting
But that doesn’t work. Apache is looking at the “./” as relative to the requested file, NOT the .htaccess file. I’d love to be able to change that to:
php_value include_path ${DOCUMENT_ROOT}/includes/
That obviously doesn’t work… Is something like this possible?
Actually whenever I put a / first, Apache is using the system path (absolute). I’ve not been able to get it to use it as a path relative to DOCUMENT_ROOT. What do you think is up with that? Are you getting a path relative to D.R. using a / first? Thanks for your help.
You see that’s the problem though. PHP uses an absolute path to the system not the web servers document_root. So you set the include_path in .htaccess and it’s either absolute (/etc/http/ etc.) OR relative to the location of the executing script. So, if it’s relative, it’s always changing depending on the depth of your executing script.
If you have a .htaccess file at the root of the site and the include_path is set to ./private/includes/, and the executing script is mysite.com/about/index.php, the include_path will then become ./about/private/includes/ - which isn’t correct.
/private/includes is a directory in my website. It’s located at the document_root. So /Library/WebServer/Documents/private/includes/
Argh! Sorry, mate! I forgot that you were dealing with the path (in your physical system rather than in the site). Doing that, all you need is the single definition of where the includes is located so /Library/WebWerver/Documents/private/includes will do the trick for you.
OK yes you are right. Make an absolute path but… the problem now is that we have a dev server and the different server setups for the live servers for each site. The path is always changing depending on the live host… and I’d love to find a way to set the include path so that it ALWAYS works. The crazy solution I posted above will do that. But it seems a little nutty. What I’d love to see is something like:
The first two entries are the default include_path. Only works in Unix btw. Windows uses ; to separate the entries. You can’t use Apache env vars there.
Permit a slight translation: You can specify a physical path for PHP scripts that are OUTSIDE the webspace, i.e., NOT under Document_Root. If all your sites are under a single directory (above DocumentRoot), then you can point there for all your domains. However, as LinhGB pointed out, the path differences between WinDoze and *Nix mean that you’ll have to include two paths to catch both (on the WILD :injured: assumption that neither OS will choke on the other’s path info).