简体   繁体   English

在.htaccess中使php_value有条件?

[英]make php_value conditional in .htaccess?

I need to set the php_value session.save_path in .htaccess. 我需要在.htaccess中设置php_value session.save_path。 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. 我的web应用程序在Windows和Linux服务器上运行,出于部署原因,我想在两个系统上保持.htaccess文件相同。

Is it possible to reference the directory where .htaccess is, in the .htaccess file itself, something like this : 是否可以在.htaccess文件中引用.htaccess所在的目录,如下所示:

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

with <%systempath> being automatically filled in on each system ? 在每个系统上自动填写<%systempath>?

You can automatically prepend a php file which will configure php with ini_set() 您可以自动添加一个php文件,该文件将使用ini_set()配置php

# .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. 这样它就可以用于目录中的任何php脚本。

in apache .htaccess for example apply php_value only a php files. 在apache .htaccess中例如只应用php_value一个php文件。

SetEnvIf Request_URI ".php$" IS_PHP
<If "-T env('IS_PHP')">
    php_value auto_prepend_file "./init.php"
</If>

I don't think this is possible with any Apache directive. 我认为任何Apache指令都不可能。

But you can do that with PHP: 但你可以用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. 这里__FILE__魔术常量 ,它保存当前PHP脚本文件的文件系统路径,而dirname返回该文件的父目录。

I know you can use some environment variables. 我知道你可以使用一些环境变量。

You can check if it will posible or not with 您可以检查它是否可用

%{ENV:variable}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM