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

时间:2012-01-04 17:29:04

标签: php apache mod-rewrite

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

关键字(如果存在)是什么来获取包含重写规则的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 个答案:

答案 0 :(得分:1)

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

您的规则应如下所示:

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