无法根据 mod_aliased 目录中存在文件进行 mod_rewrite 吗?

发布于 2024-08-11 08:50:09 字数 591 浏览 4 评论 0原文

我正在尝试在我的 .htaccess 文件中执行类似以下操作:

Alias /assets /location/of/files

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]

因此理论上它非常简单:

  • 从以 /assets/ 开头的 url 请求图像
  • apache 检查文件是否存在
  • 如果找到,则提供该文件
  • 如果没有,则运行脚本。

这在其他地方工作正常,但这是我第一次尝试在作为别名包含的目录上使用它。据我了解,Mod Rewrite 在 Mod Alias 之前运行,这肯定会导致它不起作用(事实上,我的 Alias 行位于 apache conf 中,而其余行位于 .htaccess 中)。

有没有办法让 Mod Rewrite 确认别名目录?

是否可以将 Alias 行更改为 Rewrite 行?

I'm trying to do something like the following in my .htaccess file:

Alias /assets /location/of/files

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]

So in theory it's quite straightforward:

  • an image is requested from a url starting with /assets/
  • apache checks for the existence of the file
  • if found, the file is served
  • if not, a script is run instead

This is working fine in other places but this is the first time I've tried to use it on a directory included as an Alias. As I understand it Mod Rewrite runs before Mod Alias which would surely cause this not to work (and in truth my Alias line is in the apache conf while the rest is in .htaccess).

Is there a way to get Mod Rewrite to acknowledge the Aliased directory?

Is it possible to change the Alias line to a Rewrite line instead?

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

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

发布评论

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

评论(1

旧人九事 2024-08-18 08:50:09

尝试 -F 来代替调用子请求:

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-F
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]

Try -F instead to invoke a subrequest:

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-F
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文