开发者

creating .htaccess to cache images

I want to use .htaccess file to return image i开发者_如何学Gof exists or call generators if not exists.

example :

img src="images/myimage1.jpg"

If myimage1.jpg not exists, it generates it calling createThumb.php?image=myimage1.jpg after that it returnS.

please help creating this .htaccess file


Try this:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule image/(.+)$ createThumb.php?image=$1


You can do something like this:

# Check if a JPG file doesn't exist.
RewriteCond %{DOCUMENT_ROOT}/images/$1.jpg !-f
RewriteRule ^images/(.+)$ /createThumb.php?image=$1 [QSA,L]

And then inside your createThumb.php you can create the image and store in %{DOCUMENT_ROOT}/images folder and return proper MIME type response to browser for this image after image creation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜