We want to create some kind of api where the json formatted results are generated using .php files.
The web folder looks like
api
├── .htaccess
└── foo
├── bar.php
└── baz.php
Where bar.php and baz.php are php files generating json-formatted replies on the queries.
Such files (bar.php) look like:
<?php
include_once("../../utils.php");
$id = $_GET['id'];
echo json_encode(some_function($id));
?>
Of course one should specify a header header("Content-type: application/json");. We however want to set the .htaccess to do this, such that one never forgets to set the content-type, that if additional headers are required, we can modify this easily, etc. We don't want to write header(...) in every file.
.htaccess look like:
#All php files return JSON formatted text.
AddType application/json json php
But the generated result has still mime-type: text/html.
What can cause this?