htaccess的:无法检查动态文件存在! [英] htaccess: Can't check dynamic file existence!

查看:159
本文介绍了htaccess的:无法检查动态文件存在!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了上即时缩略图的创造者通过htaccess文件看看是否被请求的文件是否存在,如果不发送用户的PHP页面来创建它。我的htaccess文件看起来是这样的:

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

似乎我的文件的存在检查不但是工作...使用%{REQUEST_FILENAME} 的作品,但这不是正确的文件名我老版本需要检查。我已经验证了新文件%1%2 - %3%4-%6.JPG 具有正确的输出,但不会触发条件!

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!

根据这个网址:

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

htaccess的文件应检查该文件是否存在:

The htaccess file should check if this file exists:

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

缩略图和htaccess文件都在同一个文件夹,但该文件夹是未知的,不能硬codeD。它需要的完整路径检查?如果是这样,我怎么能得到完整的路径,但与我的自定义文件名?

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.

推荐答案

您可以使用您的PHP脚本,以取代传统的404错误页:

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

ErrorDocument 404 thumbnail.php

然后,您可以使用PHP检索请求的URL:

Then, you can retrieve the requested URL using PHP :

$url = $_SERVER["REQUEST_URI"];

参数可以使用 preg_match 功能。

这篇关于htaccess的:无法检查动态文件存在!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆