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?
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 useForceType application/json
. So, in your vhost, you'd likely want to do something like: