I want all apache non-error responses to be sent with content-type 'application/json; charset=UTF-8'. How do I make it?

I've tried adding:

<VirtualHost *:80>
    AddType 'application/json; charset=UTF-8'

But this requires specifying file extension, I don't want to bind to file extensions since I'm not requesting specific files, but resources like this:


I've also tried DefaultType directive:

<VirtualHost *:80>
      DefaultType 'application/json; charset=UTF-8'

but this doesn't seem to be working - Content-Type:text/html; charset=utf-8 is returned. Am I missing something?


You can use Apache's ForceType directive, explained in the documentation. You have to use it in a Directory, Location, or Files context. For JSON, you'd want to use ForceType application/json. So, in your vhost, you'd likely want to do something like:

<VirtualHost *:80>
     <Location />
          ForceType application/json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.