我是 php 初学者。
我使用 XAMP 在 Apache 服务器上运行我的 php 后端。
现在我已经在我的 .htaccess 文件中创建了路线。
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^not-found/?$ pages-404.php [NC,L] # Handle requests for "not-found"
RewriteRule ^api/addUser?$ _addUser.php [NC,L]
RewriteRule ^api/login?$ _loginUser.php [NC,L]
RewriteRule ^api/logout?$ _logoutUser.php [NC,L]
ErrorDocument 404 /pages-404.php
我通过链接
https://localhost/api/login/
发送发布请求以在数据库中添加用户。
但是我收到这个错误
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache/2.4.58 (Win64) OpenSSL/3.1.3 PHP/8.0.30 Server at localhost Port 443</address>
</body>
</html>
但是,如果我尝试直接向
https://localhost/api/_loginUser.php
发送帖子请求。运行成功。
现在我似乎无法弄清楚 .htaccess 文件有什么问题。
一种解决方案是修改以下部分中的httpd.conf。
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
#
# 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>
但这也没有帮助。
您是否授予用户访问数据库的权限或将访问者存储到数据库中?因为如果您授予用户访问数据库的权限,您可以直接从 phpmyadmin 执行此操作,并编辑 config.ini 文件的 false 部分并将其替换为 grant。在将用户存储到数据库的另一半中,您可以使用 GET变量。