: 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
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
More posts by @Angela700
2 Comments
Sorted by latest first Latest Oldest Best
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.
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>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.