php - Apache 重写语法中 PHP 的 dirname(__FILE__) 的等价物?

标签 php apache mod-rewrite

图像是从 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/

相关文章:

javascript - 多个ajax倒数计时器的建议(每秒调用一次)

python - Flask 应用程序在 Xampp 中返回 404

php - PHP 中的 ApacheBench 和 http 请求

regex - 使用可选参数重写规则以在 .htaccess 中进行重定向

php - .htaccess 用于具有多个变量的友好 URL

php - Composer 要求 "laravelcollective/html":"^5.4.0"在 Laravel 6.2 中不起作用

PHP:从字符串中删除 http://、http://www、https://、https://并获取域名和 TLD

apache - abc/xyz/myfile 的 .htaccess RewriteRule?s=t

php - 通过 cURL 发送 JSON 始终返回 "No access"

php - mod_rewrite 和 mod_userdir 的问题