图像是从 Apache 公共(public)文件夹之外的文件夹提供的,不需要别名。
如果存在,获取包含重写规则的 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]
最佳答案
您无法访问 .htaccess 目录之外的文件,即使使用绝对路径也是如此。解决方案可能是在当前文件夹中创建指向您的图像目录的符号链接(symbolic link),然后将您的 .htaccess 规则指向该文件。
你的规则应该是这样的:
RewriteRule ^images/(.*)$ /assets/images/$1 [L] #this is relative to your .htaccess file
关于php - Apache 重写语法中 PHP 的 dirname(__FILE__) 的等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8731212/