Mobile app version of vmapp.org
Login or Join
Angela700

: How to set the Content-Type for SVG files parsed by PHP I currently use the following Apache httpd conf: <FilesMatch ".svg$"> SetHandler application/x-httpd-php </FilesMatch> AddType

@Angela700

Posted in: #Apache2 #Php #Svg

I currently use the following Apache httpd conf:

<FilesMatch ".svg$">
SetHandler application/x-httpd-php
</FilesMatch>
AddType image/svg+xml .svg


What I'm trying to achieve:


Parsing the PHP scripts in my SVG files
Serving my SVG files with the image/svg+xml MIME type


However, the AddType seems to be ignored now that I've set it to use the alternative handler for my SVG files. They're now served as text/html.

How can I make the httpd parse the PHP in my SVG files while preserving its image/svg+xml type?

I currently include a header("Content-type: image/svg+xml"); call in my SVG file to solve this, although I'd rather have a global way of doing this instead of having to insert this into all of my SVG files.


CentOS 6.5
Apache 2.2.15
PHP 5.3.3

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Angela700

2 Comments

Sorted by latest first Latest Oldest Best

 

@Si4351233

I ended up setting the handler for SVG files to application/x-httpd-php, and used apache's mod_headers to pass the correct content-type header.

<Files "*.svg">
SetHandler application/x-httpd-php
Header set Content-Type "image/svg+xml"
</Files>


This was solved when I found a nearly identical question at serverfault.com/questions/348439/how-to-fix-apache-content-type-for-php-parsed-css.

10% popularity Vote Up Vote Down


 

@Heady270

The Apache mod_mime documentation states that SetHandler overrides AddType:


While mod_mime associates metadata with filename extensions, the core server provides directives that are used to associate all the files in a given container (e.g., <Location>, <Directory>, or <Files>) with particular metadata. These directives include ForceType, SetHandler, SetInputFilter, and SetOutputFilter. The core directives override any filename extension mappings defined in mod_mime.


You should be able to use the header directive from mod_headers in .htaccess to make it work:

<FilesMatch ".svg$">
SetHandler application/x-httpd-php
Header set Content-Type "image/svg+xml"
</FilesMatch>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme