我有一个index.php
文件,看起来像这样:
print('Url = ' . $_SERVER['REQUEST_URI']);
return;
当我这样做的时候:
$> curl http://localhost:8888/notapi/test
Url = /notapi/test
但是,当我这样做时:
$> curl http://localhost:8888/api/test
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
you@example.com to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>
我得到一个错误500,只是通过设置url从notapi
(或任何)到api
。
是什么导致这个错误?我猜在某个地方的文件中有一些东西说/api
是一个特殊的url,重定向到其他地方,但是,作为PHP api的初学者,我不知道这可能来自哪里。
.htaccess
文件:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]
编辑:
在我的/Applications/MAMP/logs/php_error.log
中没有什么可以炫耀的。我在后台tail
它,所以我可以在显示错误时获得更新(与tail -f /Applications/MAMP/logs/php_error.log &
),但当我做我的curl
调用时没有显示任何内容。
我查看了我的.zsh_history
,看看我编辑了哪些文件。
不是我想的php.ini
,而是httpd.conf
。
我添加了这些行:
# Custom reverse proxy
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /api/ http://localhost:8888/
ProxyPassReverseCookiePath / /api/
ProxyPassReverseCookieDomain / localhost:8888
<Location "/api/">
ProxyPassReverse /
</Location>
我注释掉了所有包含/api/
的行,像这样:
# Custom reverse proxy
ProxyRequests Off
ProxyPreserveHost on
# ProxyPass /api/ http://localhost:8888/
# ProxyPassReverseCookiePath / /api/
ProxyPassReverseCookieDomain / localhost:8888
# <Location "/api/">
# ProxyPassReverse /
# </Location>
我重新启动了MAMP,现在我的curl
调用工作了。
(但是,我添加了这个,以便与一个扑动应用程序链接,现在不再工作了。但这是另一个问题。