htaccess:转发到PHP文件的特定目录请求
因此,我正在为 CMS 编写一个动态缩略图生成器,并试图找到处理请求的最佳方法。具体来说,我需要为 htaccess 文件提供 apache 代码,该代码会将所有请求发送到缩略图文件夹并将它们发送到thumbnail.php 文件。
理想情况下,如果缩略图不存在,它只会将您转发到thumbnail.php,尽管检查apache中的文件是否存在超出了我的能力范围。
请求 URL 将如下所示:
http://unknown_domain.com/unknown_folder/media/thumbnails/image-name.jpg?w=200&h=100&c=true
并且图像将存储在缩略图中像这样(或者可以是与下面相同的 URL,如果这样更有意义):
http://unknown_domain.com/unknown_folder/media/thumbnails/image -name-200-100-true.jpg
这是迄今为止我最接近的,我假设我将此 htaccess 放在缩略图文件夹中:
RewriteEngine on
#RewriteBase /unknown_folder/media/thumbnails/ # optional, depends on your setup
#Check for file existence here and forward if exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z-])-([0-9]+)-([0-9]+)-true.jpg$ thumbnail.php?w=$2&h=$2&c=true [LQSE]
谢谢如需提前提供的任何帮助!
So I am writing an on-the-fly thumbnail generator for a CMS and I am trying to find the best way to handle requests. Specifically, I need to come up with the apache code for an htaccess file that will take all requests to a thumbnail folder and send them to a thumbnail.php file instead.
Ideally it would only forward you to thumbnail.php if the thumbnail doesn't exist, although checking for file existence within apache is beyond me.
The request URL would look like this:
http://unknown_domain.com/unknown_folder/media/thumbnails/image-name.jpg?w=200&h=100&c=true
And images would be stored in the thumbnails something like this (or could be the same URL as below if that makes more sense):
http://unknown_domain.com/unknown_folder/media/thumbnails/image-name-200-100-true.jpg
Here is the closest I've come so far, I assume I put this htaccess in the thumbnails folder:
RewriteEngine on
#RewriteBase /unknown_folder/media/thumbnails/ # optional, depends on your setup
#Check for file existence here and forward if exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z-])-([0-9]+)-([0-9]+)-true.jpg$ thumbnail.php?w=$2&h=$2&c=true [LQSE]
Thank you for any help provided in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这里的问题是什么,但是您应该使用更多过滤器来检查文件是否存在......
Not sure what the question is here, but there are a few more filters you should be using to check for file existence...
我猜您正在寻找正则表达式:
我还没有测试过它,但理想情况下,应该请求
使用其参数调用脚本
thumbnail.php
。已编辑:修正了一些拼写错误和错误。
I guess you're looking for a regex:
I have not tested it, but ideally a request to
should call the script
thumbnail.php
with it's parameters.Edited: Fixed some typos and errors.