2

So, I moved into a new host. I was using some code in my htaccess to parse css files as PHP. But in this new host, it didn't work. I googled and googled and tried every code I find. All single of them didn't work. Here's some of codes I've tried:

AddHandler application/x-httpd-php .css
AddHandler application/x-httpd-php5 .css
AddHandler application/x-httpd-php53 .css
AddType application/x-httpd-php .css

My PHP version is 5.3.22 and my webhost is using Linux. But they all didn't work. Please help.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Duncan
  • 954
  • 3
  • 15
  • 23
  • possible duplicate of [Parse js/css as a PHP file using htaccess](http://stackoverflow.com/questions/10722375/parse-js-css-as-a-php-file-using-htaccess) – hjpotter92 Aug 07 '13 at 17:55
  • Curiosity grabbed me: What's the reason behind parsing CSS as PHP? I don't quite get it. Enlighten me. – Funk Forty Niner Aug 07 '13 at 17:56
  • There's a PHP code that compresses the css file @Fred – Duncan Aug 07 '13 at 17:57
  • @MarioErmando Hm... interesting. I'm going to have to look into that; including "Good 'ol Google" [**GoG**](http://www.google.com) cheers – Funk Forty Niner Aug 07 '13 at 17:58
  • @MarioErmando Have you tried the [**answer here**](http://stackoverflow.com/a/10722444/1415724), by replacing `js` with `css`? – Funk Forty Niner Aug 07 '13 at 18:00
  • Yep, still doesn't work. :( @Fred – Duncan Aug 07 '13 at 18:07
  • @MarioErmando Check what the differences are from your previous web host, if possible. Might be something in an `.ini` file, something that's pre-configured with the new service. Hard to tell, could be a number of reasons. – Funk Forty Niner Aug 07 '13 at 18:11
  • If you're going for a dynamic stylesheet, why can't you reference a .php file as your stylesheet and then use `header('Content-type: text/css');` within that file? I've seen that done many times. –  Aug 07 '13 at 18:29

2 Answers2

2

From Parse js/css as a PHP file using htaccess

You should just need to add this to your htaccess

<FilesMatch "\.css$">
  SetHandler application/x-httpd-php
  Header set Content-type "text/css"
</FilesMatch>

If you're getting a 500 Internal Server Error with the Header line, make sure you have mod_headers enabled in your apache config, if mod_headers is not installed and your provider will not install/enable it, you will need to rename your css file to .php and add into your new php file

header("Content-type: text/css");
Community
  • 1
  • 1
bizzehdee
  • 20,289
  • 11
  • 46
  • 76
  • It gives 500 Internal Server Error. – Duncan Aug 07 '13 at 18:35
  • If you're getting a 500 Internal Server Error with the Header line, make sure you have mod_headers enabled in your apache config, if it isnt installed or enabled, your out of luck and have to rename to .php – bizzehdee Aug 07 '13 at 18:36
2

I just tried making a folder called "style.css" and put a file inside called "index.php" and it works in chrome!

Of course you need to put header("Content-type: text/css"); in the php file and I'm not sure how well it works in other browsers or email clients

vahanpwns
  • 939
  • 5
  • 12