访问$ _ SERVER ['DOCUMENT_ROOT']在.htaccess文件中值中值、文件、SERVER、htaccess

2023-09-02 09:43:25 作者:偷亲xx

我需要在$ _ SERVER ['DOCUMENT_ROOT']指定的路径是在.htaccess文件访问。 有没有一种方法来访问它呢?

I need the path specified in $_SERVER['DOCUMENT_ROOT'] to be accessible in .htaccess file. Is there a way to access it there?

基本上,我需要指向一个文件保存在根目录,需要实际的文件系统路径,而不是URL路径。而是采用了硬codeD值,因此,我希望能够使用一个变量。

I basically need to point to a file kept at the root and need the actual file system path and not the URL path. So instead of using a hard coded value, I'd like to be able to use a variable.

感谢。

推荐答案

$ _ SERVER是一个PHP变量,而.htaccess文件使用Apache的配置语言。可悲的是,没有办法达到到PHP从Apache的配置文件。

$_SERVER is a PHP variable, whereas .htaccess files use Apache's configuration language. Sadly, there is no way to reach into PHP from Apache's config files.

我见过许多项目的解决方案是有一个安装脚本编写自定义的.htaccess文件进行安装应用程序时。不太理想的,更多的工作,但它能够完成任务。

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. Not quite ideal and a bit more work, but it gets the job done.