我已经写了一个dynamic的缩略图创build者的htaccess文件,看看是否存在请求的文件,如果不发送用户到PHP页面来创build它。 我的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}
的旧版本的作品,但这不是我需要检查的正确的文件名。 我已经validation了新文件%1-%2-%3-%4-%6.jpg
具有正确的输出,但不触发条件!
基于以下url:
this-is-the-image-name.gif?w=200&h=100&c=true
htaccess文件应该检查这个文件是否存在:
this-is-the-image-name-gif-200-100-true.jpg
缩略图和htaccess文件都在同一个文件夹中,但是这个文件夹是未知的,不能被硬编码。 它是否需要完整的path来检查? 如果是这样,我怎么能得到完整的path,但我的自定义文件名?
用这个拉我的头发… 请帮助! 谢谢。
您可以使用您的PHP脚本来替换传统的“404错误”页面:
ErrorDocument 404 thumbnail.php
然后,您可以使用PHP检索请求的URL:
$url = $_SERVER["REQUEST_URI"];
可以使用preg_match函数来检索参数。