Apache重写语法中PHP的dirname(__ FILE__)的等价物?

时间:2022-11-18 12:05:21

Images are served from a folder outside Apache's public folder and Aliases are not wanted.

图像从Apache公共文件夹外的文件夹提供,不需要别名。

What is the keyword, if existing, to get the real path of the htaccess that contains the rewriting rules ?

如果存在,关键字是什么,以获得包含重写规则的htaccess的真实路径?

# /website1.com/public/prod/ --> index.php & .htaccess
# /website1.com/assets/images/

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^images/(.*)$ REALPATH/../../assets/images/$1 [L] 
# REALPATH doesn't work of course

# not wanted :
# RewriteRule ^images/(.*)$ /website1.com/public/prod/assets/images/$1 [L] 

1 个解决方案

#1


1  

You can't access files outside of .htaccess directory, even using absolute path. Solution could be to make symbolic link in current folder that points to your images directory and then point your .htaccess rule to this file.

即使使用绝对路径,也无法访问.htaccess目录之外的文件。解决方案可能是在当前文件夹中创建指向图像目录的符号链接,然后将.htaccess规则指向此文件。

Your rule then should look like this:

那你的规则应该是这样的:

RewriteRule ^images/(.*)$ /assets/images/$1 [L] #this is relative to your .htaccess file

#1


1  

You can't access files outside of .htaccess directory, even using absolute path. Solution could be to make symbolic link in current folder that points to your images directory and then point your .htaccess rule to this file.

即使使用绝对路径,也无法访问.htaccess目录之外的文件。解决方案可能是在当前文件夹中创建指向图像目录的符号链接,然后将.htaccess规则指向此文件。

Your rule then should look like this:

那你的规则应该是这样的:

RewriteRule ^images/(.*)$ /assets/images/$1 [L] #this is relative to your .htaccess file