gpt4 book ai didi

apache - PHP RESTful 服务器的 mod_rewrite

转载 作者:行者123 更新时间:2023-12-02 10:00:39 26 4
gpt4 key购买 nike

我正在我的 Mac 上为本地 API 开发 PHP RESTful 服务器。

我已成功启用 mod_rewrite 并允许对站点目录 (~/Sites/api) 进行覆盖。

在~/Sites/api 中是.htaccess 文件和index.php。我想将所有请求重写为 http://localhost/~myusername/api/ * 到index.php。我需要保留查询参数,但仅此而已。

我在 .htaccess 文件中尝试了以下操作:

Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) index.php [QSA,NC,L]

这会出现 500:内部服务器错误。

注释掉 FollowSymLinks 行会出现 403:Forbidden 错误。

我可以在不进行重写的情况下正常访问index.php。

如果您能提供任何帮助,我们将不胜感激。此刻我有种想哭的感觉。

谢谢,罗斯

最佳答案

RewriteRule ^api/(.*)$ index.php?handler=$1 [L,QSA]

处理程序是传递给您的index.php 脚本的内容。例如,请求

http://localhost/~myusername/api/getUser/myusername

将被重写为

http://localhost/~myusername/api/index.php?handler=getUser/myusername

关于apache - PHP RESTful 服务器的 mod_rewrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4605039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com