.htaccess文件夹到index.php和文件到文件

I'm creating a API for a specific part of my webapplication. The API is located in the subfolder API. See the folder structure below:

- API
  - cars
     - index.php
     - count.php

However, now the tricky part. Customers will be requesting endpoints that end with JSON:

cars.json => cars/index.php cars/count.json => cars/count.php

I'm not an expert in rewrites. But is this possible?

Try this in your htaccess :

RewriteEngine on
RewriteRule ^cars\.json$ /cars/index.php [NC,L]
RewriteRule ^cars/count\.json$ /cars/count.php [NC,L]

The first Rule rewrites cars.json to cars/index.php and the second Rule Rewrites cars/count.json to cars/count.php .