简体   繁体   中英

.htaccess folder to index.php and file to file

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM