title: Prevent Apache custom error pages on JSON responses
body: <p>I'm working with an application that provides both HTML content and JSON APIs.  Using Apache, I created custom error pages for the HTML content.  The configuration uses type-maps to specify different versions of the error page based on the browser language.</p>
  
  <p>The problem is when there is an error returned by the JSON API.  That response (containing some JSON elements describing the error) is being replaced with an HTML error page.  How can I configure Apache to ignore JSON responses, returning them unmodified?</p>
  
  <p>Here's the accept header of the JSON request:</p>
  
  <pre><code>Accept:application/json, text/javascript, */*; q=0.01
  </code></pre>
  
  <p>Here are the response headers coming from the application (Tomcat):</p>
  
  <pre><code>Content-Length:23
  Content-Type:text/json;charset=UTF-8
  Date:Fri, 02 Sep 2016 15:34:03 GMT
  Server:Apache-Coyote/1.1
  </code></pre>
  
  <p>But here are the response headers that Apache is returning instead:</p>
  
  <pre><code>Accept-Ranges:bytes
  Connection:close
  Content-Language:en
  Content-Length:7628
  Content-Location:404.en.html
  Content-Type:text/html; charset=UTF-8
  Date:Fri, 02 Sep 2016 15:14:08 GMT
  Server:Apache
  TCN:choice
  Vary:negotiate,accept-language
  </code></pre>
  
  <p>Here are my configurations, for reference:</p>
  
  <p><strong>httpd.conf</strong>:</p>
  
  <pre><code>Alias /errors/ "/var/www/errors/"
  
  &lt;IfModule mod_negotiation.c&gt;
  &lt;IfModule mod_include.c&gt;
      &lt;Directory "/var/www/errors"&gt;
          AllowOverride All
          Options IncludesNoExec
          AddOutputFilter Includes html
          AddHandler type-map var
          Order allow,deny
          Allow from all
          LanguagePriority en es de fr pt
          ForceLanguagePriority Prefer Fallback
      &lt;/Directory&gt;
      ErrorDocument 404 /errors/404.var
      ErrorDocument 403 /errors/403.var
      ErrorDocument 500 /errors/500.var
      ErrorDocument 502 /errors/500.var
      ErrorDocument 503 /errors/maintenance.var
  
  &lt;/IfModule&gt;
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Here's an example of one of the .var files.  <strong>404.var</strong>:</p>
  
  <pre><code>URI: 404
  
  URI: 404.en.html
  Content-type: text/html
  Content-language: en en-US
  
  URI: 404.en-GB.html
  Content-type: text/html
  Content-language: en-GB
  
  URI: 404.fr.html
  Content-type: text/html
  Content-language: fr
  
  URI: 404.de.html
  Content-type: text/html
  Content-language: de
  
  URI: 404.es.html
  Content-type: text/html
  Content-language: es
  
  URI: 404.pt.html
  Content-type: text/html
  Content-language: pt
  </code></pre>
  
  <p>And here are some additional configurations in another .conf file, to make sure I'm including everything relevant:</p>
  
  <pre><code>ProxyRequests Off
  ProxyPreserveHost On
  ProxyErrorOverride On
  
  &lt;Proxy *&gt;
      Order deny,allow
      Allow from all
  &lt;/Proxy&gt;
  
  ProxyPass /server-info !
  ProxyPass /server-status !
  ProxyPass /errors !
  
  ProxyPass / http://localhost:7002/
  ProxyPassReverse / http://localhost:7002/
  
  &lt;Location /&gt;
      Order allow,deny
      Allow from all
  &lt;/Location&gt;
  </code></pre>