htaccess的绝对路径 [英] Htaccess absolute path
问题描述
是否可以获取我的".htaccess"文件的绝对路径?
Is it possible to get the absolut path to my ".htaccess" file?
我使用它在每个文件中加载 init.php
.
Im using this to load init.php
in every file.
php_value auto_prepend_file /Applications/XAMPP/xamppfiles/htdocs/init.php
有没有办法让我不必写绝对路径?
Is there a way so I don't have to write the absolute path?
像这样,如果 init.php
与 .htaccess
文件属于同一类别:
Like this, if init.php
is in the same category as the .htaccess
file:
php_value auto_prepend_file [ABSOLUTE_PATH_TO_HTACCESS]/init.php
,如果可能的话,我该怎么写,但仍要返回一个目录(因为 init.php
位于 public_html
外部,其中 .htaccess
是).
and if that is possible, how do I write that but still go back one directory (Since init.php
is outside public_html
, where the .htaccess
is).
谢谢.
推荐答案
我使用PHP创建.htaccess文件来解决它.
I solved it with using PHP to create the .htaccess file.
使用要放入htaccess文件中的所有内容创建htaccess.php文件.
Create a htaccess.php file with all the things you want to put in the htaccess file.
php_value auto_prepend_file [INIT]init.php
然后使用正确的权限创建一个空的 .htaccess
文件.
Then create a empty .htaccess
file with the correct permissions.
然后运行下面的类,并将[INIT]替换为绝对路径.
Then run the class below and replace [INIT] with the absolute path.
这是生成.htaccess文件的类:
Here is the class to generate the .htaccess file:
<?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);
}
}
?>
这篇关于htaccess的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!