路由在调试列表中,但在Symfony 4中返回404 [英] Route is in debug list but returns 404 in Symfony 4
问题描述
好,所以我刚刚安装了最新版本的Symfony4.安装后运行浏览器,并显示一个很好的欢迎问候.一切都好!
Ok, so I just installed latest version Symfony 4. Run the browser after installation and a nice welcome greeting shows. All good!
然后我使用make:controller
创建了一个新的控制器.我将此控制器命名为Client,并且正在使用Annotations,与其他Default Controller相同.我将路由配置如下:
Then I created a new controller using make:controller
. I named this controller Client and is using Annotations, same with the other Default Controller. I configured the routing as follows:
/**
* @Route("/client", name="client")
*/
public function index()
{
// replace this line with your own code!
return $this->render('@Maker/demoPage.html.twig', [ 'path' => str_replace($this->getParameter('kernel.project_dir').'/', '', __FILE__) ]);
}
我刷新了浏览器,一切正常,没有错误.
I refreshed the browser and all good, no errors.
然后我在浏览器中手动键入路径以检查它是否确实有效:
Then I manually typed the path into the browser to check if it's really working:
localhost:8000/client
问题.网址传回标准apache 404
Problem. The url returned standard apache 404
Not Found
The requested URL /client was not found on this server.
Apache/2.4.18 (Ubuntu) Server at new.staff-fdr.dev Port 80
调试路径可以看到以下内容:
The debug route sees this though:
-------------------------- -------- -------- ------ ------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------
client ANY ANY ANY /client
index ANY ANY ANY /
_twig_error_test ANY ANY ANY /_error/{code}.
推荐答案
缺少.htaccess
文件.
composer config extra.symfony.allow-contrib true
composer req symfony/apache-pack
这篇关于路由在调试列表中,但在Symfony 4中返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!