【发布时间】:2011-05-25 10:30:15
【问题描述】:
我有一个包含很多图片的网站。假设这些图像存储在文件夹“/data/images”中。我还有一个带有水印图像的文件夹:“/data/wimages”。原始图像和水印图像的文件名相同,但并非所有图像都有水印副本。因此,如果存在水印副本,我想重定向原始图像(而不更改其在浏览器或 html 源代码中的 URL),如果没有,则传递原始图像。我正在尝试使用 Apache mod_rewrite 解决这个问题:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f # Checking if file exists and is a regular file.
RewriteCond %{REQUEST_URI} ^.*/data/images/.*\.(gif|jp?g|png)$ [NC] # Is file an image?
RewriteRule ^data/images/(.*\.(gif|png|jp?g))$ /data/wimages/$1 [NC] # New watermaked image url.
RewriteCond %{REQUEST_FILENAME} !-f # If watermarked image not exists ..
RewriteRule ^data/wimages/(.*\.(gif|png|jp?g))$ /data/images/$1 [NC,L]
然后我正在恢复之前更改的 url 并获得一个无限循环!
有什么想法吗?
附:对不起我的英语。
【问题讨论】:
标签: apache mod-rewrite