views:

464

answers:

2

I'm working on a website that has a number of style sheets all of which need to be handled as php scripts server-side. My .htaccess file looks something like this:

<FilesMatch "\.(css)$">
    ForceType application/x-httpd-php
</FilesMatch>

This causes a small problem as the mime type of the http-response's Content-Type field is then set to text/html instead of text/css. Obviously I can fix this by adding header('Content-Type: text/css') to all my files but is there a better way? Can I do this from within the .htaccess file? None of the directives offered by mod_mime or mod_negotiation seem to be what I'm looking for.

+6  A: 

try:

php_value default_mimetype "text/css"
Cal
+1  A: 

You should be able to just add a .php extension to all of your CSS files; this will cause the server to pass all of the "normal" CSS as just that, whereas all of your dynamic, PHP-generated CSS should be parsed. After that, it's just a matter of slightly modifying the way in which you link your stylesheets:

<link rel="stylesheet" type="text/css" href="styles.css.php" />

Though that's always done the trick for me, there's a slight chance you may need to explicitly declare the MIME type of your CSS files using PHP's header() function, like so:

header('Content-type: text/css');
Hexagon Theory