Apache的.htaccess中的AddHandler Conditionnal的服务器名或IP服务器、htaccess、Apache、AddHandler

2023-09-02 20:34:58 作者:余生一个他

我在Site5主办我的分期和生产服务器,一个比较好的托管商海事组织。问题不在于他们的质量,更多的涉及到PHP的版本问题。

I'm hosting my staging and production servers at Site5, a relatively good hoster IMO. The question is not about their quality but more about an issue related to PHP's version.

我们的开发服务器使用PHP 5.3这是一个很好的版本,5.4是太新了,我们不希望使用它的功能还不够wides $ P $垫。

Our development server is using PHP 5.3 which is a good version, 5.4 being too new, we don't want to use it's features yet, not enough widespread.

但问题是,Site5使用PHP 5.2在默认情况下,但你可以使用.htaccess的AddHandler语句改为5.3。工作正常Site5但我们的开发服务器崩溃时,我们保持这种说法在的.htaccess文件。

Problem is, Site5 uses PHP 5.2 by default but you can change to 5.3 using an HTACCESS AddHandler statement. Works fine on Site5 but our dev server crashes when we keep that statement in the HTAccess file.

如果您使用SVN / Git的部署你的web应用程序,你知道你始终保持相同的文件随处可见,因此多数民众赞成在那里疼,我似乎无法找到有关的.htaccess文件AddHandler的条件语句什么。我可以写上重写引擎条件下容易,但我找不到任何会看起来和用起来是这样的:

If you use SVN/Git to deploy your web apps, you know that you always keep the same files everywhere, so thats where it hurts, i can't seem to find anything about conditional statements for HTACCESS files for AddHandler. I can write conditions on the rewrite engine easily, but i can't find anything that would look and act like this:

#<If SERVERNAME == "targethost.com">
#    PHP 5.3 configuration for site5
#    AddHandler application/x-httpd-php53 .php
#</If>

任何人有一个解决方案?

Anyone has a solution?

推荐答案

因为Apache 2.4,你可以在你的.htaccess文件中使用的前pression:

Since Apache 2.4 you can use this expression in your .htaccess files:

<If "%{HTTP_HOST} == 'example.com'">
    AddHandler application/x-httpd-php53 .php
</If>

https://httpd.apache.org/docs/2.4/expr。 HTML#范例

请注意,这并不在Apache 2.2的工作。

Note that this does not work in Apache 2.2.