如何检查 .htaccess 中是否未定义变量?

How to check if a variable is undefined in .htaccess?

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

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

RewriteBase /

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

我以为!^$可以检测未定义的变量,但是不行。

在你想要的东西中:

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

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