0

I have a fairly high traffic web server and would like to squeeze some micro optimization out of it.

In Apache's config I have:

SetEnvIfNoCase Request_URI "\.a?png$" dontlog SetEnvIfNoCase Request_URI "\.bmp$" dontlog SetEnvIfNoCase Request_URI "\.css$" dontlog ...several more 

I'd like to achieve this (pseudo-code):

<If env=!dontlog> SetEnvIfNoCase Request_URI "\.a?png$" dontlog </If> <If env=!dontlog> SetEnvIfNoCase Request_URI "\.bmp$" dontlog </If> <If env=!dontlog> SetEnvIfNoCase Request_URI "\.css$" dontlog </If> ...several more 

Performing a config test using my pseudo-code results in:

AH00526: Syntax error on line 260 of C:/apache24/conf/httpd.conf: Cannot parse condition clause: syntax error, unexpected T_OP_STR_EQ, expecting '('


Note:

Please ignore the regex triviality of the examples. How can I perform short-circuiting?

1 Answer 1

0

SetEnvIfNoCase performs regular expression matching in a case-insensitive manner.

So rather than finding a complex work-around to avoid processing separate SetEnvIfNoCase tests and multiple trivial regular expressions, reduce your test to a single, slightly more complex, regular expression that matches all file extensions you don't want to log.

SetEnvIfNoCase Request_URI "\.(?:jpe?g|css|bmp|a?png)$" dontlog 

Also consider storing and serving your images in a separate subdomain. If you believe logging an unnecessary performance penalty, that allows you to configure a VirtualHost without any logging, which then completely avoids the need for separate testing if a request should or shouldn't be logged.

People claim that an images / static content subdomain will improve pagespeed because a browser can open additional connections to the subdomain, you don't have to set/process cookies there etc. etc. And even if you don't want to use a CDN for your main site, you can still easily use one for your static content.

3
  • Thank you, I am aware that I can combine those simple regexes into a larger one but it doesn't lend itself well to readability especially if encountered by someone who is not me in the future. I have several much more complicated regexes which perform ip-based restrictions which would benefit from short-circuiting; CIDR notation is not feasible for our networking madness. We have 3 million page hits a month and on average 30-50 assets being loaded. Commented Mar 27, 2024 at 14:08
  • People can't answer questions you don't ask and for which you don't provide the right context or incomplete information. To me your question is only about how to make your attempted solution work, where IMHO your attempted solution is the completely wrong approach to reduce the number SetEnvIfNoCase Request_URI directives that need to be processed. - If you have a different question, ask that, with full context rather then how to make your (possibly wrong) attempted approach work. Commented Mar 27, 2024 at 14:51
  • I disagree. I asked I'd like to achieve this (pseudo-code): not "help me combine this regex". Your desire to take the path of least resistance was your choice. Commented Mar 27, 2024 at 15:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.