Sunday, 15 July 2012

Have Apache/PHP set MIME type based upon file extension for files being executed as PHP -



Have Apache/PHP set MIME type based upon file extension for files being executed as PHP -

i have apache/php based server on i've made apache execute js, html , css files php via next line in /etc/mime.types:

application/x-httpd-php phtml pht php js html css

we did because though files save .html/.js/.css exclusively non-php, need bit of templating in them (for example, changing domain of urls depending upon whether on live or testing server).

the problem is, method of making apache treat files php causes them returned wrong mime type, @ to the lowest degree breaks css files in chromium , has nasty effects in other browsers too.

is there way can tell apache execute these files php still output them right mime type file extension? don't want have manually paste

<?php header("content-type: text/css"); ?>

at top of of our .css files.

we did because though files save .html/.js/.css exclusively non-php, need bit of templating in them

why not dynamic parts in main document then, dynamic anyway? running resources through php interpreter such waste.

for javascript:

<script> domain = "<? echo $domain; ?>"; <----- dynamic bits here </script> <script src="xyz.js"></script> <----- can utilize them in xyz.js

for css:

<link rel="stylesheet" href="stylesheet.css"> <style type="text/css"> /* insert dynamic css here, overriding parts static style sheet */ .my_div { color: <? echo $color; ?> } </style>

php apache mime-types

No comments:

Post a Comment