是否有可能获得我的".htaccess“文件的绝对路径?
我使用它在每个文件中加载init.php。
php_value auto_prepend_file /Applications/XAMPP/xamppfiles/htdocs/init.php有没有办法这样我就不用写绝对路径了?
像这样,如果init.php与.htaccess文件属于同一类别:
php_value auto_prepend_file [ABSOLUTE_PATH_TO_HTACCESS]/init.php如果这是可能的话,我如何编写它,但仍然返回一个目录(因为init.php在public_html之外,.htaccess在那里)。
提前谢谢。
发布于 2015-08-24 08:30:29
我通过使用PHP创建.htaccess文件来解决这个问题。
创建一个htaccess.php文件,其中包含您想要放在htaccess文件中的所有内容。
php_value auto_prepend_file [INIT]init.php然后创建一个具有正确权限的空.htaccess文件。
然后运行下面的类并用绝对路径替换INIT。
下面是生成.htaccess文件的类:
<?php
class Install {
public static function htaccess(){
$file = ".htaccess";
ob_start();
include "htaccess.php";
$htaccess = ob_get_contents();
ob_end_clean();
$absolute = __DIR__;
$init = $absolute;
$init = str_replace("public_html", "", $init);
$htaccess = str_replace("[INIT]", $init, $htaccess);
$opFile = fopen($file, 'w');
file_put_contents($file, $htaccess, FILE_APPEND);
fclose($opFile);
}
}
?>发布于 2015-07-30 13:12:51
假设已接受的答案here上的更新响应有效,并且您的相对目录结构如您所描述的那样:
[docroot]
|
\- init.php
|
\- public_html
|
\- .htaccess
|
\- index.php然后,通过包含指令,您应该可以将一个目录放到您希望预先添加的init.php文件中。
php_value auto_prepend_file ./../init.php在.htaccess文件中。
https://stackoverflow.com/questions/31561191
复制相似问题