Error 404 with slim framework

半世苍凉 提交于 2019-12-08 06:45:19

问题


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(); 

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.

The .htaccess file is as follows:

RewriteEngine ON

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

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.


回答1:


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.

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]


来源:https://stackoverflow.com/questions/15128346/error-404-with-slim-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!