开发者

creating .htaccess to cache images

开发者 https://www.devze.com 2023-02-22 19:12 出处:网络
I want to use .htaccessfile to return image i开发者_如何学Gof exists or call generators if not exists.

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

精彩评论

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