改变.PHP做.PNG

时间:2013-09-24 13:32:06

标签: php regex .htaccess mod-rewrite

我有一个动态图像脚本,使用此标记显示图像上的用户信息

<img src="http://domain.com/dynamicimage.php" />

使用.hatccess?

以任何方式将.PHP更改为.PNG

2 个答案:

答案 0 :(得分:0)

您无需为此更新.htaccess。 如果你不介意src属性中的.php扩展名,你可以简单地确保php脚本为png内容生成正确的标题。例如:

 header('Content-Length: '.strlen($imgesrcstring));
 header('Content-Type: image/png');

如果您注意.php扩展名,则需要在.htaccess中添加一些内容以进行重写设置,以便dynamicimage.php处理对dynamicimage.png的任何请求

在这种情况下,请看一下这个问题:

Apache - rewrite images to php file with .htaccess

答案 1 :(得分:-1)

启用mod_rewrite.htaccesshttpd.conf,然后将此代码放在.htaccess DOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(dynamicimage)\.php$ /$1.png [L,NC,R=301]