2015-10-04 50 views
2

我有一个Slim框架(版本2)的问题。如果我在默认页面上运行,它会显示没有问题的内容,但是当我请求类似$app->get('/test'...的路由时,我总是会收到404错误。Slim Framework只返回404

这是我的index.php。

<?php 
require 'vendor/autoload.php'; 

\Slim\Slim::registerAutoloader(); 

$app = new Slim\Slim(); 

// Welcome message. 
$app->get("/", function() use($app) { 
    echo 'Appointment API<br />'; 
}); 

$app->get("/test", function() use($app) { 
    echo "This is a test"; 
}); 

$app->run(); 

我的.htaccess文件:

RewriteEngine On 

# Some hosts may require you to use the `RewriteBase` directive. 
# If you need to use the `RewriteBase` directive, it should be the 
# absolute physical path to the directory that contains this htaccess file. 
# 
#RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 

而且我作曲文件:

{ 
    "require": { 
     "slim/slim": "^2.6", 
     "slim/extras": "*", 
     "slim/middleware": "*" 
    } 
} 

为了这一点,我真的不知道该怎么办。

+0

是由Apache或纤细提供404错误? – Federkun

+0

该错误由Slim提供。我从slim得到默认错误页面 –

+1

对我来说似乎很好。你可以尝试通过'/ index.php/test'访问吗? – Federkun

回答

0

用途:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 

如果你仍然得到404,那么这个问题是不是你的.htaccess

+1

为什么只是简单地删除请求与现有目录不匹配的条件?你认为它如何解决OP问题? –

0

如果你得到404,这意味着,如果模式改写enabled.if并不比先启用它,然后用下面的改变的.htaccess和它的作品的.htaccess问题:

<ifModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L] 
</ifModule>