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


.htaccess folder to index.php and file to file

我正在为我的web应用程序的特定部分创建API。该API位于子文件夹API中。查看下面的文件夹结构:

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

然而,现在是棘手的部分。客户将请求以JSON结尾的端点:

汽车。Json => cars/index.php汽车/计数。Json => cars/count.php

我不是重写的专家。但这可能吗?

在你的htaccess中试试:

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

第一条规则重写了cars。第2条规则将cars/index.php重写为cars/count。json 汽车/count.php