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.

8
  • possible duplicate of Parse js/css as a PHP file using htaccess Commented Aug 7, 2013 at 17:55
  • Curiosity grabbed me: What's the reason behind parsing CSS as PHP? I don't quite get it. Enlighten me. Commented Aug 7, 2013 at 17:56
  • There's a PHP code that compresses the css file @Fred Commented Aug 7, 2013 at 17:57
  • @MarioErmando Hm... interesting. I'm going to have to look into that; including "Good 'ol Google" GoG cheers Commented Aug 7, 2013 at 17:58
  • @MarioErmando Have you tried the answer here, by replacing js with css? Commented Aug 7, 2013 at 18:00

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

2 Comments

It gives 500 Internal Server Error.
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
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.