Htaccess绝对路径

Jac*_*cob 9 apache .htaccess

是否有可能获得我的".htaccess"文件的绝对路径?

我用它来加载init.php每个文件.

php_value auto_prepend_file /Applications/XAMPP/xamppfiles/htdocs/init.php
Run Code Online (Sandbox Code Playgroud)

有没有办法让我不必写绝对路径?

像这样,如果init.php.htaccess文件属于同一类别:

php_value auto_prepend_file [ABSOLUTE_PATH_TO_HTACCESS]/init.php
Run Code Online (Sandbox Code Playgroud)

如果可能,我该怎么写,但仍然回到一个目录(因为init.php在外面public_html,在哪里.htaccess).

提前致谢.

Jac*_*cob 0

我通过使用 PHP 创建 .htaccess 文件解决了这个问题。

创建一个 htaccess.php 文件,其中包含要放入 htaccess 文件中的所有内容。

php_value auto_prepend_file [INIT]init.php
Run Code Online (Sandbox Code Playgroud)

然后创建一个.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);

        }

    }

?>
Run Code Online (Sandbox Code Playgroud)