简体   繁体   中英

Error 404 with slim framework

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.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM