Conditional PHP Version in .htaccess

前端 未结 1 1934
闹比i
闹比i 2021-01-15 11:38

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

相关标签:
1条回答
  • 2021-01-15 12:28

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

    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
    

    Then in the cgi-sys/php-wrapper.cgi file, something like:

    #!/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
    
    0 讨论(0)
提交回复
热议问题