这个 Nginx 伪静态规则该怎么写: index. PHP ->api

2018-05-19 15:16:30 +08:00
 JohnChiu

动态链接是:www.domain.com/index.php/admin/login

伪静态是:www.domain.com/api/admin/login

没有接触过 Nginx,请问这个规则该怎么写呢

标题自动大写 php,改不过来。。。

1203 次点击
所在节点    问与答
8 条回复
JohnChiu
2018-05-19 15:58:47 +08:00
没有大佬帮一下吗~~
chinvo
2018-05-19 16:05:57 +08:00
简单点,你给放到 /api 里面,然后

try_files $uri $uri/ /index.php/$uri?$args;
Lax
2018-05-19 16:06:43 +08:00
类似这样,不保证能用:
rewrite /api/admin/login /index.php/admin/login;

如果需要匹配
rewrite ^/api/(.*) /index.php/$1;
JohnChiu
2018-05-19 16:12:18 +08:00
@chinvo #2 把 index 放到 /api 文件夹然后这样吗?没有成功,另外 index.php 后面还有其他的比如 /admin/logout
if (!-e $request_filename) {
try_files $uri $uri/ /index.php/$uri?$args;
}
chinvo
2018-05-19 16:13:29 +08:00
@JohnChiu #4 要写在 location /api 里面
JohnChiu
2018-05-19 16:16:27 +08:00
@Lax #3 感谢,不过还是没有成功,依然是要用 index.php 才能访问,api 不能访问
请问我写的有问题吗
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
JohnChiu
2018-05-19 16:19:04 +08:00
@Lax #3 发错代码了
if (!-e $request_filename) {
rewrite ^/api/(.*) /index.php/$1;
}
JohnChiu
2018-05-19 16:23:39 +08:00
@chinvo #5 感谢,按你说的搞好了
@Lax #3 感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/456136

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX