我是PHP的初学者。
我已经使用XAMP在Apache服务器上运行我的php后端。我已经在我的mysql数据库中创建了一个用户表。现在我已经在我的php后端进行了CRUD操作,以便创建用户,删除用户,更新用户和读取用户。
现在我已经在我的**.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
发送一个post请求,它会成功运行。事实上,所有与数据库中的表相关的CRUD操作都能成功运行。
但是当我把他们的路线做成这样:
RewriteRule ^api/login?$ _loginUser.php [NC,L]
型
在我的.htaccess文件里它们好像不起作用
现在我似乎无法找出什么可以是我的问题与**.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>
型
但它也没有帮助。
1条答案
按热度按时间nr7wwzry1#
你是给用户访问你的数据库还是你存储一个访问者到数据库?因为如果你给用户访问数据库,你可以直接从phpmyadmin做,编辑php.ini文件的false部分,并将其替换为granted。