2

我一直在编写一个脚本来使用 PHP 生成较低分辨率的图像副本。我正在努力使用 mod_write 仅当文件不存在时才执行 PHP 脚本

我目前拥有的(可能会有所偏差,因为我今天已经进行了数千次尝试)如下:

RewriteCond %{REQUEST_URI} (900x...|...x900)\.(png|jpe?g|gif)
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?(window_resolution=(640))(;\ .*)?$ [NC]
RewriteRule full/(.*) /responsive/cache/480/responsive/$1 [L]

RewriteCond %{REQUEST_URI} (.*)(900x...|...x900)\.(png|jpe?g|gif)
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?(window_resolution=(.*))(;\ .*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/responsive/cache/%3%{REQUEST_URI} !-f
RewriteRule .* /responsive/resize.php [L]

目前文件的位置如下:

/responsive/full/photo-900x500.jpg

缓存存储:

/responsive/cache/

采用以下格式:

/responsive/cache/<resolution>/<original path>

我想要文件的示例:

/responsive/cache/768/responsive/photo-900x500.jpg

理想情况下,这将与 wordpress 之类的东西一起使用,我会在其中制作这样的结构

缓存:

/cache/

原件:

/wp-content/uploads/*

例子:

/cache/768/wp-content/uploads/2012/01/test.jpg
4

1 回答 1

0

经过数小时的删除和重新开始,我想出了这个,它似乎工作得很好。如果我愿意,它将保留完整的文件路径,并允许通过库克选择图像大小:

RewriteCond %{ENV:REDIRECT_STATUS} $^
RewriteCond %{REQUEST_URI} (900x...|...x900)\.(png|jpe?g|gif)
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?(ricache_width=(480|640|768|992|1170))(;\ .*)?$ [NC]
RewriteRule (.*) /responsive/cache/%3/responsive/$1

RewriteCond %{ENV:REDIRECT_STATUS} $^
RewriteCond %{REQUEST_URI} (.*)(900x...|...x900)\.(png|jpe?g|gif)
RewriteCond %{HTTP_COOKIE} ^(.*;\ )?(ricache_width=(480|640|768|992|1170))(;\ .*)?$ [NC]
RewriteCond %{DOCUMENT_ROOT}/responsive/cache/%3%{REQUEST_URI} !-f
RewriteRule .* /responsive/resize.php [L]

RewriteCond %{ENV:REDIRECT_STATUS} $^
RewriteRule .* - [L]

它缺少一个 404(这没什么大不了的,我在 PHP 中有一个备份,但我需要替换它)。但至少这是一个很好的起点!:)

于 2013-01-13T17:24:12.367 回答