【问题标题】:Can I concatenate environment variables in apache config?我可以在 apache 配置中连接环境变量吗?
【发布时间】:2012-02-22 14:51:11
【问题描述】:

我在 apache 配置中有两个环境变量,我想将它们连接成一个新的环境变量。这可能吗?

我意识到这不起作用,但它展示了我所追求的那种东西:

SetEnv one foo
SetEnv two bar
SetEnv three one+two

...然后“三”的值为“foobar”

【问题讨论】:

    标签: apache mod-rewrite environment-variables concatenation setenv


    【解决方案1】:

    使用带有两个通配符反向引用的 mod_rewrite 正则表达式来访问环境变量并连接字符串:

    #This will be true for any user agent
    RewriteCond  %{HTTP_USER_AGENT}  ^.*
    
    #Replace / with / and set the new environment variable
    RewriteRule  /(%{ENV:one})*(%{ENV:two})* / [E=three:$1$2]
    

    【讨论】:

    • 谢谢。我只是希望我能记住为什么我想知道,现在! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2015-06-11
    • 2015-01-29
    • 1970-01-01
    • 2013-07-09
    相关资源
    最近更新 更多