2

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'
</VirtualHost>

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:

http://my.domain.com/rest/articles/

I've also tried DefaultType directive:

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

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

1
3

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
     </Location>
</VirtualHost>
0

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.