php - XAMPP:错误 404 找不到对象!调用 API 时在此服务器上未找到请求的 URL
问题描述
我在 Windows 10 中使用 xampp 运行登录时调用 API 的 slimframework。
如果我键入 localhost/maps.html,则可以访问该站点,但如果我尝试单击 index.html 中的登录按钮,则不会调用登录 API。
我已经配置了httpd
and httpd-vhosts
,该站点可以在本地访问,但是每当我尝试单击 index.html 中的登录按钮时,都会出现此错误消息:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.43 (Win64) OpenSSL/1.1.1g PHP/7.4.7
这是我的目录结构的样子:
在根文件夹下:
-index.php
-maps.html
-index.html
-admin/
-js/
-vendor/
-.htaccess
在 index.html 中:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Maps</title>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/login.js"></script>
<script type="text/javascript" src="js/lib/jquery.cookie.js"></script>
<link rel="icon" href="favicon.ico" />
</head>
<body>
<div id="header">
<h1 data-bind="text:site_title"></h1>
</div>
<div id="login_container">
<div id="login_view">
<div>
<input id="loginid" type="text" data-bind="value: loginid, event:{keypress:kpLoginId}" placeholder="LoginID" />
</div>
<div>
<input id="password" type="password" data-bind="value: password, event:{keypress:kpPassword}" placeholder="Password" />
</div>
<div>
<button id="login" data-bind="click: login">Login</button>
</div>
</div>
</div>
<div data-bind="visible: failed">
Cannot Login
</div>
</body>
</html>
在 httpd.conf 中:
DocumentRoot "C:\xampp\htdocs\myslimsite\web_src"
<Directory "C:\xampp\htdocs\myslimsite\web_src">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html index.php index.pl index.cgi index.asp index.shtml index.htm \
default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>
.htaccess 内部:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/api/v1/(.*)$ /index.php/$1 [QSA,L]
除了 httpd.conf 和 httpd-vhosts.conf 之外,是否需要配置任何其他设置才能使其他页面正常工作?谢谢你。
解决方案
重写规则 ^/api/v1/(.*)$ /index.php/$1 [QSA,L]
这不是 Slim 的工作方式。您必须将内部重定向添加到“前端控制器”。前端控制器是 index.php 文件。然后在 Slim 中定义路由,而不是在.htaccess
文件中。
请先阅读文档:
推荐阅读
- javascript - D3 叶节点 - 许多元素重叠
- java - Web应用MongoDB数据库结构
- html - 无法使导航栏水平
- android - 在 linux 上反应原生“SDK 目录 '/Users/USERNAME/Library/Android/sdk' 不存在。”
- html - 用 :hover 和 :hover:after改变内容
- scala - 如何注册 sparklistener 以处理 spark worker 进程
- javascript - React + Express:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段 access-control-allow-origin
- c# - 在 ASP.NET MVC 项目中使用 Rotativa
- python-3.x - NAN 有时在训练我的 yolo tensorflow 模型以进行损失时使用相同的图像
- c - C 为什么 for 循环没有像它应该的那样迭代多次?