在.htaccess有条件的PHP版本 [英] Conditional PHP Version in .htaccess

查看:250
本文介绍了在.htaccess有条件的PHP版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地测试服务器我使用PHP 5.4。在现场主持人,但我目前只限于PHP 5.3,它必须在.htaccess(否则默认为5.2)来指定。

On my local testing server I'm using PHP 5.4. On the live host, however, I'm currently limited to PHP 5.3 and it must be specified in .htaccess (otherwise it defaults to 5.2).

所以,我可以添加:

# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php

这活主机上的伟大工程,但打破了本地测试服务器。

which works great on the live host but breaks the local testing server.

是否有可能使用类似mod_rewrite的为条件指定一个PHP基于域的版本?还是有更好的办法? .htaccess文件被跟踪(GIT),我想保持这种方式,如果可能的。

Is it possible to use something like mod_rewrite to conditionally specify a PHP version based on the domain? Or is there a better way? The .htaccess file is tracked (git) and I'd like to keep it that way if possible.

我想同样的问题被要求<一href="http://stackoverflow.com/questions/12957362/apache-htaccess-addhandler-conditionnal-on-servername-or-ip">here,但我没有一个动态的部署方法来实现(比在混帐推/拉一些简单的bash等)。

I think the same question is being asked here, but I don't have a dynamic deployment method implemented (other than some simple bash during git push/pull).

推荐答案

有没有办法做到这一点动态地使用mod_rewrite。

There's no way to do this dynamically using mod_rewrite.

您可以尝试指向你的动作中性PHP包装器,可以检测它是否需要执行的cgi-SYS / php53 或PHP 5.4的版本。线沿线的东西:

You could try pointing your Action to a neutral php wrapper that can detect whether it needs to run cgi-sys/php53 or the PHP 5.4 version. Something along the lines of:

Action php-cgi /cgi-sys/php-wrapper.cgi
AddHandler php-cgi .php

然后在的cgi-SYS / PHP-wrapper.cgi 文件,是这样的:

#!/bin/sh

# check if this is the php 5.3 environment
if [ -x "/path/to/cgi-sys/php53" ]; then
    # execute php 5.3
    export PHPRC=/path/to/php5.3/rc
    exec /path/to/cgi-sys/php53
else 
    # else, run php 5.4
    export PHPRC=/path/to/php5.4/rc
    exec /path/to/cgi-sys/php54
fi

这篇关于在.htaccess有条件的PHP版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆