【问题标题】:How to check if a variable is undefined in .htaccess?如何检查.htaccess中是否未定义变量?
【发布时间】:2019-05-11 06:55:56
【问题描述】:

我知道我可以在httpd.conf 中设置一个自定义变量,以便在.htaccess 中访问。我想让我的代码万无一失,这样当新程序员在新机器上设置它时,它就不会轻易出错。

如何从.htaccess 内部检查未定义的变量,以便在有人忘记在httpd.conf 中设置变量时仍然可以运行它?

RewriteBase /

RewriteCond ${ServerBase} !^$
RewriteBase ${ServerBase}

我以为!^$ 可以检测到未定义的变量,但是没有。

【问题讨论】:

    标签: apache .htaccess mod-rewrite environment-variables httpd.conf


    【解决方案1】:

    你想要这个:

    <IfDefine ${ServerBase}>
    ...
    </IfDefine >
    

    转到指令定义,此处的文档:https://httpd.apache.org/docs/2.4/mod/core.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 2012-04-28
      • 2018-05-26
      • 1970-01-01
      • 2021-01-31
      • 2011-12-10
      • 1970-01-01
      相关资源
      最近更新 更多