.htaccess 中的 Zend SetEnv 不起作用

发布于 2024-11-03 04:10:19 字数 395 浏览 1 评论 0原文

我在我的 ubuntu 主服务器上安装了 Zend。在我的 .htaccess 文件中,我有以下代码:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

当我在公共文件夹的 index.php 中回显 APPLICATION_ENV 时,未设置 APPLICATION_ENV。

我做错了什么?

Apache 中启用了 Mod 重写。

I installed Zend on my ubuntu homeserver. In my .htaccess file i have the following code:

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

When i echo APPLICATION_ENV in my index.php in the public folder, APPLICATION_ENV is not set.

What am i doing wrong?

Mod rewrite is enabled in apache.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

又怨 2024-11-10 04:10:19

为了在 .htaccess 文件中使用 SetEnv,我相信您需要

AllowOverride FileInfo

在相关的虚拟主机目录块中设置... ...。 (然后像往常一样重新启动 httpd 服务。)

此外,根据您运行 PHP 的方式,此类信息可能会被删除。 (例如:suexec 将有效删除所有非 HTTP* 环境变量。)

In order to use SetEnv within a .htaccess file, I believe you need to set...

AllowOverride FileInfo

...within the relevant virtualhost directory block. (And then restart the httpd service as per usual.)

Additionally, depending on how you're running PHP, it's possible that such information is being stripped out. (e.g.: suexec will effectively remove all non-HTTP* environment vars.)

蓝眸 2024-11-10 04:10:19

您还可以使用:

RewriteRule .* - [E=ENV_NAME_HERE:ENV_VALUE_HERE]

You can also use:

RewriteRule .* - [E=ENV_NAME_HERE:ENV_VALUE_HERE]
农村范ル 2024-11-10 04:10:19

首先,您需要安装mod_env(和mod_rewrite),

仔细检查Apache是​​否已加载以下模块:

apachectl -l
或者
httpd -l

该命令可能会根据我认为的操作系统发行版而有所不同。

为了使 .htaccess 文件正常工作,您需要AllowOveride All,它可以在不同的配置文件(和“部分”)中设置,具体取决于您的操作系统作为 Apache 的配置方式。您最好的选择是查明这是 htaccess 文件问题还是环境一. 在主配置文件中的任意位置设置:

SetEnv TESTME foobar

重新启动 Apache 并从 PHP 脚本中回显 TEST 如果获得了它,请调试 .htaccess

注意 1:限制在虚拟主机中使用.htacess 到您真正需要的文件夹或将配置移动到虚拟主机。

注意 2:如果您安装了 Apache mod_dir,您可能不需要所有这些重写规则。它

First You need mod_env installed (and mod_rewrite)

Double check if Apache has the module(s) loaded with either:

apachectl -l
or
httpd -l

the command might be different according to OS distribution i believe.

For the .htaccess file to work you need AllowOveride All which can be set in different configuration files (and "parts" depending on the way your OS as Apache configured. Your best option is to find out if it is a htaccess file issue or an environment one. Set anywhere in main configuration file:

SetEnv TESTME foobar

restart Apache and echo TEST from a PHP script. If you got it, debug the .htaccess

Note 1: Restrict in your virtual host the usage of .htacess to the folder where you really need it or move the configurations to a virtual host.

Note 2: You probably don't need all those rewrite rules if you have Apache mod_dir installed. Have a look at it

魔法唧唧 2024-11-10 04:10:19

我更喜欢将 SetEnv 放在本地服务器的 httpd.conf 文件中,以便我的所有本地 ZF 应用程序都在开发模式下运行,当我推送到登台服务器时,它有一个标志将环境设置为登台,然后是生产服务器没有这样的设置,因此它默认为生产...

这样我可以在源代码管理中保留相同的 .htaccess 文件,当我将其推送到不同的服务器时,它会按预期运行。

middaparka 关于 suExec 的说法是正确的...suExec 会阻止您在 .htaccess 文件中设置自定义环境变量 - 根据 WebFaction 论坛上的 remi 的说法。

I prefer to put SetEnv in the httpd.conf file for the local server, so that all my local ZF apps run in development mode, and when I push to the staging server it has a flag to Set the environment to staging, then the production server has no such setting so it defaults to production...

This way I can keep the same .htaccess file in source control and when I push it out to the different servers it behaves as expected.

middaparka is right about suExec... suExec prevents you from setting custom environment variables in your .htaccess file - according to remi at the WebFaction forum.

一刻暧昧 2024-11-10 04:10:19

如果您在 Mac 上运行家庭服务器或启用了 suEXEC,则会采取安全措施来删除已定义的任何非 http 环境变量,因此它们不会出现在 $_ENV['APPLICATION_ENV'] 中。但是,您可以通过 PHP 函数访问它们以获得相同的结果。

$var = apache_getenv('APPLICATION_ENV');

如果需要,您甚至可以在 PHP 中定义环境变量,但不推荐。

$_ENV['APPLICATION_ENV'] = apache_getenv('APPLICATION_ENV');

我有一个与你几乎相同的配置,我们只是定义一个全局的:

define('APPLICATION_ENV', apache_getenv('APPLICATION_ENV'));

一旦你这样做了,它应该按预期工作。

If you are running your home server on a Mac or have suEXEC enabled, there are security measures in place to strip any non-http environment variables that are defined, therefore they won't appear in $_ENV['APPLICATION_ENV']. You CAN, however access these through a PHP function to get the same thing.

$var = apache_getenv('APPLICATION_ENV');

You could even define the environment variable within PHP if you want, although not recommended.

$_ENV['APPLICATION_ENV'] = apache_getenv('APPLICATION_ENV');

I have an almost identical config to what you have, and we just define a global:

define('APPLICATION_ENV', apache_getenv('APPLICATION_ENV'));

Once you do that, it should work as desired.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文