【问题标题】:Slim framework error apacheSlim 框架错误 apache
【发布时间】:2017-08-28 18:25:06
【问题描述】:

我的应用程序无法使用 Slim Framework 和 apache。

Route Slim,不起作用

$app->group("/teste", function() {
    $this->get("/", function(Request $request, Response $response, $args = []) {
        return $response->write("deu");
    });

    $this->get("/:nome", function(Request $request, Response $response, $args = []) {
        return $response->write("deu ".$args['nome']);
    });
});

.htaccess in use 和 index.php(Slim) 在同一位置:public_html/slim/biblioteca/

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

尝试访问路由/teste/时返回错误500

可能需要配置或创建 httpd.conf 并启用 .htaccess?也允许覆盖所有。

在 /etc/ 中未找到此文件

可以帮助我吗?

Printscreen 项目列表文件

【问题讨论】:

  • 检查您的错误日志以查看导致 500 的原因。

标签: php linux apache .htaccess slim


【解决方案1】:

在 .htaccess 文件中添加以下代码

RewriteEngine On

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with,content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

像下面的例子一样定义根:

\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();

$app->post('/example', 'examplefunction');

希望能成功

【讨论】:

    【解决方案2】:

    在 .htaccess 文件中使用下面的代码就可以了

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多