0

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?

0

1 Answer 1

1

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 .

Sign up to request clarification or add additional context in comments.

3 Comments

I've placed the .htaccess file in the API directory and now it throws an internal server error. Did I do something wrong?
probably because the path the user request is much longer. is it http:example.org/api/cars.json
True, full path is gate.carsdomain.com/branche/api/cars.json and gate.carsdomain.com/branche/api/cars/count.json. So where should I place the .htaccess and is that one still correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.