Apache 2.4 and 500 Errors in Htaccess

I upgraded my main server from Ubuntu 12.04 to 14.04 yesterday and after the upgrade Apache didn’t want to serve anything but 500 errors. Turns out that Ubuntu 14.04 brings with it an upgrade to Apache 2.4 (used to be 2.2). One of many issues were errors stemming from .htaccess files. Here’s how to fix those.

I copied a lot of my htaccess files directly from the HTML5 Boilerplate project. Turns out that’s not the best idea if you run Apache 2.4. If you’re looking at your error logs and seeing something about a filter chain, the issue is a new syntax for mod_filter. Look for the line in your .htaccess file that starts with <IfModule filter_module>. Replace that whole block with this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<IfModule filter_module>
  FilterDeclare   COMPRESS
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/html'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/css'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/plain'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'text/x-component'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/javascript'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/json'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/xhtml+xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/rss+xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/atom+xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/vnd.ms-fontobject'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'image/svg+xml'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'image/x-icon'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'application/x-font-ttf'"
  FilterProvider  COMPRESS  DEFLATE "%{CONTENT_TYPE} = 'font/opentype'"
  FilterChain     COMPRESS
  FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
</IfModule>

It’s exactly the same thing as before, just updated to use the new syntax. There’s yet another Apache module you can use to switch between the different syntaxes but I’d prefer not to run anything more than I really need.

See the official discussion on this issue here.

Server administration, Web development

« Backup and Restore a MySQL Database Should I Load Google Web Fonts JS API or the CSS Link? »

Comments