nginx regex help needed

following various tutorials on the intarwebs, i've managed to get a drupal site [which was previously on apache] up and running on nginx… with one major hiccup:

my site's theme has embedded PHP within some of its CSS files, to define colours/dimensions etc [for ease of making global changes]. under apache, i had set PHP to handle these CSS files by putting the following in an .htaccess file in the theme directory:

AddHandler application/x-httpd-php .css
php_value default_mimetype "text/css"

now, obviously the PHP inside these CSS files is no longer being parsed with the new nginx setup, so that the site layout is all over the show. what i need to do is tell nginx to hand over any CSS files it finds within /sites//themes/ to php-fastcgi for processing, but unfortunately 99% of regex is 'alphabetti spaghetti' to me, so i'm not sure how i'd construct such a directive in the correct syntax.

can some regex guru give me a few pointers?

2 Replies

You shouldn't need any fancy regex try this

location ~* /sites//themes//(.*).css$

{

//stuff to pass to php-fastcgi

}

It basically means all files in the sites//themes// directory that end in .css will be passed to php-fastcgi

If you want all .css files to be passed to php which is what AddHandler will have done in apache use

location ~* .css

{

//stuff to pass to php

}

cheers for that.

unfortunately it didnae work. drupal is still ignoring the CSS file with the PHP embedded in it.

for now, i've just gone through and removed all the PHP conditionals from the CSS file and hardwired everything in instead - and it's working fine now

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct