我目前有一个使用Slim Framework构建的 api.php 文件。我想使用 api.mydomain.com(或 mydomain.com/api)之类的东西来引用 API 文件并使用http://api.mydomain.com作为基本 url 进行调用。Slim 文档要求将以下内容添加到您的 .htacess 文件中:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
但如果我是正确的,如果请求的文件不存在,则返回 index.php 文件。如何最好地设置从 api.mydomain.com 或 mydomain.com/api 到 index.php 的重写?我们发现的所有内容都指向使用 .htaccess 进行配置。
我们使用了以下重写规则,但这导致我们的所有 URL 都附加了斜杠('/'),这也需要我们在 Slim 中重新配置我们的路由。(例如:“/messages”变成“/messages/”,“/threads?id=123”变成“/threads/?id=123”)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^api\.mydomain\.com [NC]
RewriteRule ^ api.php [QSA,L]