![](/img/trans.png)
[英]Codeigniter on xampp error: The requested URL was not found on this server
[英]XAMPP: Error 404 Object not found! The requested URL was not found on this server when calling APIs
我在 Windows 10 中使用 xampp 來運行在登錄時調用 API 的 slimframework。
如果我輸入 localhost/maps.html,可以訪問該站點,但是如果我嘗試單擊 index.html 中的登錄按鈕,則不會調用登錄 API。
我已經配置了httpd
和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
內部索引.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
文件中。
請先閱讀文檔:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.