[英]Routes not working on Slim framework
I am learning the slim framework. 我正在学习苗条的框架。 I got a point where I have to set up my webserver such that I can see something like http://slimapp instead of http://localhost/slimapp/public/index.php . 我有一点我必须设置我的网络服务器,以便我可以看到像http:// slimapp而不是http://localhost/slimapp/public/index.php 。
I have included a .htaccess file in the public folder of my project like so 我已经在我的项目的公共文件夹中包含了一个.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
I have also set up a virtual host on my wamp server 我还在我的wamp服务器上设置了一个虚拟主机
<VirtualHost *:80>
DocumentRoot "C:\wamp64\www\slimapp\public"
ServerName slimapp
<Directory "C:\wamp64\www\slimapp\public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I have also added this to my hosts file 我还将此添加到我的hosts文件中
127.0.0.1 slimapp
I restarted my server but I get a 'Not Found' error when I try to access my routes. 我重新启动了我的服务器但是当我尝试访问我的路由时出现“未找到”错误。
"Not Found
The requested URL /hello/uche was not found on this server."
This is my index.php file 这是我的index.php文件
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response) {
$name = $request->getAttribute('name');
$response->getBody()->write("Hello, $name");
return $response;
});
$app->run();
Please help me here. 请帮帮我。
尝试将.htaccess文件移动到根目录
In case someone still face this problem, this is how I solved it: 如果有人仍然面临这个问题,我就是这样解决的:
Enable model rewrite. 启用模型重写。 In your terminal type: 在您的终端类型中:
sudo a2enmod rewrite && sudo service apache2 restart sudo a2enmod重写&& sudo服务apache2 restart
http://help.slimframework.com/discussions/problems/10216-beginner-routes-not-working http://help.slimframework.com/discussions/problems/10216-beginner-routes-not-working
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.