Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make php_value conditional in .htaccess?

I need to set the php_value session.save_path in .htaccess. This seems to require a full path, a relative path doesn't seem to work.

My webapplication runs on both Windows and Linux servers and I'd like to keep the .htaccess file the same on both systems, for deployment reasons.

Is it possible to reference the directory where .htaccess is, in the .htaccess file itself, something like this :

php_value session.save_path "<%systempath>/sessions"

with <%systempath> being automatically filled in on each system ?

like image 595
Dylan Avatar asked Feb 10 '11 13:02

Dylan


2 Answers

You can automatically prepend a php file which will configure php with ini_set()

# .htaccess
php_value auto_prepend_file "autoprepend.php"

Then:

// autoprepend.php
ini_set('session.save_path', __DIR__ . '/sessions');

This way it will work for any php script within the directory.

like image 158
Max Tsepkov Avatar answered Sep 29 '22 04:09

Max Tsepkov


I don’t think this is possible with any Apache directive.

But you can do that with PHP:

ini_set('session.save_path', dirname(__FILE__).'/sessions');

Here __FILE__ is the magic constant that holds the file system path to the current PHP script file and dirname returns the parent directory of that file.

like image 26
Gumbo Avatar answered Sep 29 '22 05:09

Gumbo