使用瘦框架时出现错误 404 [英] Error 404 with slim framework

查看:31
本文介绍了使用瘦框架时出现错误 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习用 PHP 和 mysql 编写代码,需要能够使用 wampserver 运行 PHP 文件.我已经正确安装了 wamp 并通过 Windows 8 将其在线,但是当我去运行我的 PHP 文件时,我总是出现错误 404.我确保我的 Slim 文件和 .php 文件在正确的目录中,我也修改了.htaccess 相应地,以便在未找到 URL 时重新路由到正确的文件,因为我正在本地计算机上测试它.这是我的一些示例代码:

I am learning to code in PHP and mysql and need to be able to run PHP files using a wampserver. I have correctly installed wamp and have it online through Windows 8, however when I go to run my PHP file I am always given Error 404. I have ensured that my Slim file and .php file are in the correct directory and I have also modified the .htaccess accordingly so that it reroutes to the proper file if a URL is not found since I am testing this on my local machine. Here is a some of my sample code:

require 'C:\wamp\www\easysites\codeguy-Slim-b8181de\Slim\Slim.php';
        \Slim\Slim::registerAutoloader();

        $api = new \Slim\Slim();

        $api->run(); 

我已将错误追踪到 $api->run() 并且在某个时刻从调用堆栈中得到一个错误,表明 Slim 的 environment.php 中第 123 行发生了错误,该处首先处理 URL.如果我运行由 Netbeans 生成的基本 index.php 文件,我会得到通常的文本,提醒我它正在工作,但是尝试使用 Slim 运行 php 文件它会出错,这些文件位于 root 下的同一子目录中.Slim 已由 php 文件正确加载,但不允许我运行其他任何内容,从而阻止我看到已导入的数据库.

I have traced the error to $api->run() and was getting an error from the call stack at one point that indicated an error had happened in Slim's environment.php at line 123 where the URL is first dealt with. If I run the basic index.php file generated by Netbeans, I get the usual text that alerts me that it is working, however try to run the php file using Slim it errors out which are in the same sub directory under root. Slim is correctly loaded by the php file, but will not allow me to run anything else thus preventing me from seeing the database that I have imported.

有没有人知道可能出了什么问题?我有一位同事成功运行了该文件,但我们无法使用相同类型的更改使其在我的机器上运行.

Does anyone have an idea of what could be going wrong? I have a co-worker who has successfully run the file but we are unable to make it run on my machine using the same types of changes.

.htaccess文件如下:

The .htaccess file is as follows:

RewriteEngine ON

RewriteRule ^API(.*)$ /API/api.php [QSA, L]

我尝试运行的文件位于名为 API 的根目录中包含的文件夹中,而我尝试运行的文件是 api.php.

The file I am trying to run is in a folder contained in the root directory named API, and the file I am trying to run is api.php.

推荐答案

当我完全按照安装 slim 的所有说明(在本地 Windows 机器上的 easyphp 上安装)时,我收到错误 404.

When I followed all the instructions of the installation of slim exactly (installing it on easyphp on my local windows machine), I got the error 404.

我将 .htaccess 更改为以下内容,然后它工作正常:

I changed the .htaccess to the following, and then it worked fine:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

这篇关于使用瘦框架时出现错误 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆