ge-6ren">
gpt4 book ai didi

php - Slim 框架报错 apache

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:31 26 4
gpt4 key购买 nike

我的应用程序无法使用 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 正在使用 和 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 项目列表文件

enter image description here

最佳答案

在 .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');

希望一切顺利

关于php - Slim 框架报错 apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41568939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com