尝试进行 htaccess URL 重写
我正在尝试使用参数将 API 调用重定向到 api.php,但它不起作用。
RewriteCond %{REQUEST_URI} ^/widgetapi
RewriteRule ^widgetapi/(.*)/(.*)$ api.php?action=$1&string=$2 [L]
我怎样才能实现这个目标?我希望所有类似于 /widgetapi/cook/bacon
的调用都映射到 /api.php?action=cook&string=bacon
。现在似乎有些东西被重写了,但我看到的是白页而不是 api.php 输出。
Apache版本是2.2,规则在.htaccess中,RewriteEngine处于On状态(其他URL按预期重写)。
I'm trying to redirect API calls to api.php with parameters, but it doesn't work.
RewriteCond %{REQUEST_URI} ^/widgetapi
RewriteRule ^widgetapi/(.*)/(.*)$ api.php?action=$1&string=$2 [L]
How can I achieve this? I want all calls similar to /widgetapi/cook/bacon
map to /api.php?action=cook&string=bacon
. Right now it seems that something is rewritten, but I see white page instead of api.php output.
Apache version is 2.2, rules are in .htaccess, RewriteEngine is On (other URLs are rewritten as intended).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这个重写规则似乎有效。白页实际上是 api.php 输出,因为我编写了
$items = []
而不是$items = array()
。All right, this rewrite rule seems to work. White page was actually api.php output because I've written
$items = []
instead of$items = array()
.