Apache 2.4 – HTTP Header Regex Match Guide

apache-2.4regex

I have a header in apache that is too long, so I want to turn it into a subset. The header is a string and I'm trying to get it to become this subset: WANTED_SUBSTRING_MATCH(everything in between) [but not the first colon]. which is in regex: /wanted_substring_match(.+)[^:]/

Is it possible to achieve this in apache? I've been trying to get <If> to work to no avail. I have also tried: <If %{MY-Header} =~ /wanted_substring_match(.+)[^:]/> but it doesn't match… this is likely because the =~ keyword means an exact match?

Best Answer

It should be %{HTTP:MY-Header} in an Apache Expression to match your header. And the (.+) should go after the [^:] to match anything except a colon.