Apache 2.4 Unrecognized header format %
Using Apache 2.4 and followed the examples here https://httpd.apache.org/docs/2.4/expr.html
Here is my code
<If "!%{REQUEST_URI} =~ m#files/cache/static/[A-Za-z_\-0-9]+.cache#">
Header set foo-checksum "expr=%{md5:foo}"
</If>
I'm just playing at the moment but as soon as I use
Header set foo-checksum "expr=%{md5:foo}"
As per their example - I get
AH00526: Syntax error on line 130 of /etc/httpd/conf/httpd.conf:
httpd[19459]: Unrecognized header format %
httpd.service: main process exited, code=exited, status=1/FAILURE
On apache start. Any ideas? I've tried it outside of an expression as well and it gives the same error
Other expressions work.
You need to be using Apache v2.4.10 or above and as Ubuntu 14.04 LTS ships with v2.4.7 this is most likely what you are using. The documentation mentions this briefly at the start of the Header directive docs:
Compatibility: SetIfEmpty available in 2.4.7 and later, expr=value available in 2.4.10 and later
I ran up a couple of servers to confirm this works
Apache v2.4.12:
root@ubuntu-server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 15.10
Release: 15.10
Codename: wily
root@ubuntu-server:~# cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
Header set foo-checksum "expr=%{md5:foo}"
</VirtualHost>
root@ubuntu-server:~# apachectl -v
Server version: Apache/2.4.12 (Ubuntu)
Server built: Jul 24 2015 15:59:00
root@ubuntu-server:~# service apache2 reload
root@ubuntu-server:~# curl -I localhost
HTTP/1.1 200 OK
Date: Mon, 07 Mar 2016 21:15:38 GMT
Server: Apache/2.4.12 (Ubuntu)
Last-Modified: Mon, 07 Mar 2016 20:57:04 GMT
ETag: "2c39-52d7bb502f118"
Accept-Ranges: bytes
Content-Length: 11321
Vary: Accept-Encoding
foo-checksum: acbd18db4cc2f85cedef654fccc4a4d8
Content-Type: text/html
but not on Apache v2.4.7:
root@ubuntu-server:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
root@ubuntu-server:~# cat /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
Header set foo-checksum "expr=%{md5:foo}"
</VirtualHost>
root@ubuntu-server:~# apachectl -v
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jan 14 2016 17:45:23
root@ubuntu-server:~# service apache2 reload
* Reloading web server apache2 *
* The apache2 configtest failed. Not doing anything.
Output of config test was:
AH00526: Syntax error on line 2 of /etc/apache2/sites-enabled/000-default.conf:
Unrecognized header format %
Action 'configtest' failed.
The Apache error log may have more information.