我有一个小的 php 脚本,可以生成论坛签名的图像 (GD)。要调用它们,有一个类似以下的网址:http://www.example.net/img/imgtype_NN.png
地点: - imgtype 是我想要的签名类型 - NN是图像的ID
当我调用此网址时,我想测试该图像是否已存在于目录中(即是否已生成),在本例中我想显示它。
否则我希望我的脚本生成它然后显示它。
这是我实际的 .htaccess :
RewriteCond %{REQUEST_URI} img/(.*)_(.*).png$
RewriteCond %{DOCUMENT_ROOT}/signatures/img/%1_%2.png -f
RewriteRule img/(.*)_(.*).png$ /signatures/img/$1_$2.png [L]
RewriteRule img/(.*)_(.*).png /signatures/signatures.php?signature=$1&id_pop=$2 [L]
图像存储在 example.com/signatures/img/中,php 脚本位于 example.com/signatures/signatures.php
经过几个小时的尝试,我没有完全得到我需要的东西,我现在放弃了,我需要一些帮助。
谢谢大家!
最佳答案
好吧,您的代码不是最好的,所以您的问题可能是由于某些语法错误造成的。
无论如何,你可以尝试这个版本(将此代码放入你的root htaccess中)
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/signatures/img/$1_$2\.png -f
RewriteRule ^img/(.+)_(.+)\.png$ /signatures/img/$1_$2.png [L]
RewriteRule ^img/(.+)_(.+)\.png$ /signatures/signatures.php?signature=$1&id_pop=$2 [L]
确保您已在 Apache 配置中启用 mod_rewrite 并允许 htaccess
关于php - RewriteCond : if image exist then show it, 否则生成它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332039/