开发者

htaccess: Can't check dynamic file existence!

I have written a on-the-fly thumbnail creator by an htaccess file looking to see if the requested file exists and if not sending the user to a php page to create it. My htaccess file looks like this:

# 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

My check of the file's existence does not seem to work however... the old version that uses %{REQUEST_FILENAME} works, but that is not the correct filename I need to check. I have verified that the new file %1-%2-%3-%4-%6.jpg has the correct output, but does not trigger the condition!

Based on this URL:

this-is-the-image-name.gif?w=200&h=100&c=true

The htaccess file should check if this file exists:

this-is-the-image-name-gif-200-100-true.jpg

The thumbnails and htaccess file are both in the same folder, but this folder is unknown and can't be hardcoded. Does it need the full path to check? If so, how can I get the full path but with my custom filename?

Pulling my hair out with this one... PLEASE help! Thank you.


You can use your PHP script to replace the traditional "404 Error" page :

ErrorDocument 404 thumbnail.php

Then, you can retrieve the requested URL using PHP :

$url = $_SERVER["REQUEST_URI"];

Parameters can be retrieved using the preg_match function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜