Duncan
Duncan

Reputation: 964

Parse CSS file as PHP

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.

Upvotes: 2

Views: 4109

Answers (2)

vahanpwns
vahanpwns

Reputation: 963

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

Upvotes: 2

bizzehdee
bizzehdee

Reputation: 20993

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");

Upvotes: 2

Related Questions