相当于 Apache 重写语法中的 PHP 目录名(__FILE__)?

发布于 2024-12-25 00:41:37 字数 451 浏览 0 评论 0原文

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

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

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

# /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] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天气好吗我好吗 2025-01-01 00:41:37

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

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

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

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.

Your rule then should look like this:

RewriteRule ^images/(.*)$ /assets/images/$1 [L] #this is relative to your .htaccess file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文