RewriteCond 和别名

发布于 2024-08-29 01:25:33 字数 476 浏览 2 评论 0原文

我定义了如下所示的别名:

Alias /pictures/sm/ /var/www/my_site/data/_active_thumbnails/

稍后在 VirtualHost 部分有:

DocumentRoot    /var/www/my_site/sites/www.my_site.com/htdocs

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/thumbnails/(.*)\.(jpg|JPG)    /images/stg-list-img.png [PT,L]

我想做的是仅当驱动器上不存在原始图像时才显示 /images/stg-list-img.png 占位符图像。

现在它正在替换/thumbnails/ 中的所有图像。看起来 RewriteCond 不知道别名。有办法克服吗?

谢谢

I have defined alias that looks like this:

Alias /pictures/sm/ /var/www/my_site/data/_active_thumbnails/

Later in the VirtualHost section have:

DocumentRoot    /var/www/my_site/sites/www.my_site.com/htdocs

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/thumbnails/(.*)\.(jpg|JPG)    /images/stg-list-img.png [PT,L]

What I'm trying to do is to display /images/stg-list-img.png placeholder image only if the original image does not exist on the drive.

Right now it's replacing all the images from /thumbnails/. It looks like the RewriteCond is not aware about the Alias. Is there the way to overcome it?

Thanks

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

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

发布评论

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

评论(1

宛菡 2024-09-05 01:25:33

REQUEST_FILENAME 只是完整的文件系统路径,当您将它与 htaccess 中的规则一起使用时,或者在每个虚拟主机配置中,就像您拥有的那样,它仍然只是 URI。

这主要是因为Apache现阶段还没有机会将其映射到任何文件。

您可以将前缀添加到您的 -f 测试中,或全部:将您的规则放入 ,添加重写库 /pictures/sm/ ,并更改您的规则的正则表达式...

但是,您的正则表达式目前没有任何意义。如果别名很重要并且是 /pictures/sm,则重写规则永远无法与 ^/thumbnails 匹配。

REQUEST_FILENAME is only the full filesystem path wnen you use it with your rules in htaccess or -- in per-virtualhost config like you have it's still just the URI.

This is mainly because Apache hasn't yet had a chance to map it to any file at this stage.

You could just add the prefix to your -f test, or all of: put your rules in , adding a Rewritebase /pictures/sm/, and changing your rule's regex...

However, your regex doesn't currently make any sense. If the Alias matters and is /pictures/sm, the rewriterule could never match with ^/thumbnails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文