【发布时间】:2014-05-10 15:47:43
【问题描述】:
我正在尝试创建一个简单的类似“Hello World”的 API,为此我需要一个规则来将 URL 重定向/重写到我的 API。
假设我的文件名为index.php,所以每当我将GET 设为index.php 时,我都会得到items 的列表。
我要做的第一件事是将 URL mydomain.com/index.php 重定向到 mydomain.com/api。
其次,当mydomain.com/api被访问时,我希望服务器在不重写URL的情况下触发index.php文件。
我当前的代码如下所示:
location /api {
rewrite ^ $scheme://$host/index.php permanent;
}
location /index.php{
return 302 www.mydomain.com/api;
}
但它没有按预期工作。为什么以及如何解决?
【问题讨论】:
标签: redirect nginx webserver rewrite