Mic*_*ael 2 php .htaccess parsing png image
我用PHP创建了一个动态PNG图片.为了使用PNG扩展,我创建了一个.htaccess-File,其中包含以下内容:
AddType application/x-httpd-php .png
Run Code Online (Sandbox Code Playgroud)
在我的本地XAMPP服务器上一切都很完美,但在网络服务器上传文件之后它就再也无法工作了.当我访问该文件时,将显示该文件的PHP代码.
以下是两个服务器的两个不同答案:
本地服务器:
HTTP/1.1 200 OK
Date: Tue, 16 Oct 2012 21:51:58 GMT
Server: Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
Last-Modified: Sat, 07 Feb 2009 11:47:04 GMT
Etag: "9000000024598-1e66-46252b23c9e00"
Accept-Ranges: bytes
Content-Length: 7782
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: image/x-icon
Run Code Online (Sandbox Code Playgroud)
网络服务器:
HTTP/1.1 200 OK
Date: Tue, 16 Oct 2012 21:55:17 GMT
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r
Last-Modified: Tue, 16 Oct 2012 21:21:56 GMT
Etag: "db0f1b0-afc-4cc33be6befa5"
Accept-Ranges: bytes
Content-Length: 2812
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Content-Type: application/x-httpd-php
Run Code Online (Sandbox Code Playgroud)
所以不知何故文件没有被解析.我真的不知道从哪里开始.
我认为你最好使用.htaccessRewriteEngine这样:
RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^logo\.png$ logo.php
Run Code Online (Sandbox Code Playgroud)
或者对于所有.php文件:
RewriteEngine On
RewriteBase /directory/to/dynamic_image
RewriteRule ^(.+)\.png$ $1.php
Run Code Online (Sandbox Code Playgroud)