简体   繁体   English

访问.htaccess文件中的$ _SERVER ['DOCUMENT_ROOT']值

[英]Accessing $_SERVER['DOCUMENT_ROOT'] value in .htaccess file

I need the path specified in $_SERVER['DOCUMENT_ROOT'] to be accessible in .htaccess file. 我需要在.htaccess文件中访问$ _SERVER ['DOCUMENT_ROOT']中指定的路径。 Is there a way to access it there? 有没有办法在那里访问它?

I basically need to point to a file kept at the root and need the actual file system path and not the URL path. 我基本上需要指向保存在根目录的文件,并且需要实际的文件系统路径而不是URL路径。 So instead of using a hard coded value, I'd like to be able to use a variable. 因此,我不想使用硬编码值,而是希望能够使用变量。

Thanks. 谢谢。

我相信%{DOCUMENT_ROOT}仅适用于RewriteCond

$_SERVER is a PHP variable, whereas .htaccess files use Apache's configuration language. $ _SERVER是一个PHP变量,而.htaccess文件使用Apache的配置语言。 Sadly, there is no way to reach into PHP from Apache's config files. 遗憾的是,没有办法从Apache的配置文件进入PHP。

The solution I've seen in many projects is to have an installation script write a customized .htaccess file out when the application is installed. 我在许多项目中看到的解决方案是安装脚本在安装应用程序时写出自定义的.htaccess文件。 Not quite ideal and a bit more work, but it gets the job done. 不太理想和更多的工作,但它完成了工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM