RewriteCond 和别名
我定义了如下所示的别名:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.