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.
精彩评论