使用htaccess相对于htaccess文件自动添加PHP文件

使用htaccess相对于htaccess文件自动添加PHP文件

本文介绍了使用htaccess相对于htaccess文件自动添加PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过:

php_value auto_prepend_file "file.php"

在我的 .htaccess 中,该文件位于 public_html

in my .htaccess that is in public_html folder.

现在,当我运行 public_html / sub / index.php 时,出现此错误:

Now when I run public_html/sub/index.php i get this error :

Fatal error: Unknown: Failed opening required 'file.php'

如何使用 auto_prepend_file 标志包含与 .htaccess相关的文件文件?

How to use auto_prepend_file flag to include a file relative to .htaccess file ?

推荐答案

文件必须位于PHP的 include_path 内部。因此,您必须将文件目录设置为php.ini内的 include_path ,或使用 php_value 语句。

The file must be inside PHP's include_path. So you must either set the file's directory to be in the include_path inside php.ini, or do it in the .htaccess with a php_value statement.

php_value include_path ".:/path/to/file_directory"
php_value auto_prepend_file "file.php"

如果在.htaccess中使用上述方法,请务必复制<$ c php.ini中的$ c> include_path 并添加:/ path_to / file_directory ,这样您就不会丢失任何已经需要的包含文件。

If you use the above method in .htaccess, be sure to copy the include_path from php.ini in and add the :/path_to/file_directory so you don't lose any already needed includes.

或者,只需将:/ path / to / file_directory 添加到 include_path 直接在php.ini中

Alternatively, just add :/path/to/file_directory to include_path directly in the php.ini

如果无法修改include_path,则可以尝试指定 auto_prepend_file 的相对路径。这应该起作用,因为发送的文件路径的处理方式与使用 require()进行了相同处理:

If you cannot modify the include_path, you might try specifying a relative path to the auto_prepend_file. This should work since the file path sent is processed identically as if it was called with require():

php_value auto_prepend_file "./file.php"

这篇关于使用htaccess相对于htaccess文件自动添加PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:39