【发布时间】:2011-09-12 06:01:46
【问题描述】:
我已经通过 htaccess 文件编写了一个即时缩略图创建器,以查看请求的文件是否存在,如果不将用户发送到 php 页面来创建它。我的 htaccess 文件如下所示:
# Check the formatting (this works)
RewriteCond %{SCRIPT_FILENAME}%{QUERY_STRING} /([a-zA-Z0-9-]+).(jpg|gif|png)w=([0-9]+)&h=([0-9]+)(&c=(true|false))
# Only forward to thumbnail.php if file doesn't exist
#RewriteCond %{REQUEST_FILENAME} !-f #this works but not for the correct filename!
RewriteCond %1-%2-%3-%4-%6.jpg !-f # Doesn't work!!!
# If file doesn't exist, send here: (this works)
RewriteRule ^.*$ thumbnail.php?file_name=%1&type=%2&w=%3&h=%4&c=%6
我对文件是否存在的检查似乎不起作用...使用%{REQUEST_FILENAME} 的旧版本有效,但这不是我需要检查的正确文件名。我已经验证了新文件%1-%2-%3-%4-%6.jpg有正确的输出,但是没有触发条件!
基于此网址:
this-is-the-image-name.gif?w=200&h=100&c=true
htaccess 文件应该检查这个文件是否存在:
this-is-the-image-name-gif-200-100-true.jpg
缩略图和 htaccess 文件都在同一个文件夹中,但这个文件夹是未知的,不能硬编码。是否需要完整路径才能检查?如果是这样,我怎样才能获得完整路径但使用我的自定义文件名?
用这个把我的头发拉出来……请帮忙!谢谢。
【问题讨论】:
-
这是一个很好的 mod-rewrite 问题,我正在添加 mod-rewrite 标签,但你应该尝试在 ServFault 上提问,你会在这个地方找到一些 mod-rewrite 天才。
-
thumbnail.php 文件在哪里?
-
@Creadiff thumbnail.php 文件与要检查的缩略图文件位于同一目录 (media/thumbnails/)。
标签: apache .htaccess mod-rewrite conditional filepath